[Catalyst] Where should constraints go

Carl Franks fireartist at gmail.com
Fri Nov 3 15:01:06 GMT 2006


On 03/11/06, Ian Docherty <ian at iandocherty.com> wrote:
> Where should the various constraint values go in my MVC structure? For
> example the Model defines the size of each field in (for example) a
> username field in the User database table as being 16 characters max.
>
> I am using FormValidator to validate the username field by calling a
> validation routine in the Model-User as you can see in the code snippets
> below.
>
> In the example of the username, the constraints are in the length (no
> more than 16 characters) and in the 'existing' to ensure that a username
> is not chosen that already exists.
>
> This seems to make sense to me since it is the Model that knows the
> constraints of the database. If I were to do other (business logic) type
> constraints then I would probably put in a business logic layer where
> these constraints were defined.
>
> The problem is in the View. To give a text error message that 'Must be
> between 1 and 16 characters' is hard-coding a constraint directly in the
> view which would need to be changed if the database schema changed.
>
> I cannot think of a 'clean' way of getting these database constraints
> from the Model into the View.
>
> Anybody else tackled this issue?

I made on very basic start [1] on being able to automatically create
constraints from the database column types. At the moment it only
supports mysql, and it's also probably very out-of-sync with the
current svn trunk - but I'd /really/ like to see it finished, and I
/really/ don't have any time to work on it, so if you want to take a
look and do something with it, that'd be great.
My primary goal was to get it working with HTML::Widget as
H-W-Constraint-DBIC [2], but there's no reason it couldn't be
integrated with any other validation package.

[1] http://dev.catalyst.perl.org/repos/bast/branches/DBIx-Class/columns_info_for
[2] http://dev.catalystframework.org/repos/Catalyst/trunk/HTML-Widget-Constraint-DBIC/

Carl



More information about the Catalyst mailing list