[Catalyst] Form validation in insert() and update()?

mla maurice.aubrey at gmail.com
Mon May 14 21:44:57 GMT 2007


Wade.Stuart at fallon.com wrote:
> mla <maurice.aubrey at gmail.com> wrote on 05/14/2007 02:45:49 PM:
> 
>> I'm studying different frameworks for a new project.
>> I'm very new to Catalyst and am reading through the tutorial.
>> In part 8, advanced CRUD, there's an example of form validation.
>>
>> The approach is very similar to what I've always used
>> but I've been looking at Rails recently and noticed that they
>> run the validation code at the point the ORM is saved/updated.
>>
>> What are the thoughts on this? It does seem kind of elegant to
>> not have the validation tied to a specific html form. That *any*
>> attempt to modify an ORM object would, regardless of source,
>> hit the same validation checks and produce the same errors.
>  
> It gets hard.  The validation state depends on the controller more than you
> would think.  My old projects pushed the validation from my Model,  the
> problem is that while some data may be technically valid for the database
> tables,  depending on the controller's use and intent it may not be valid
> for that state.  I have since started to tie the Validation in the
> Controller files and it seems to be saving me a lot of bouncing while
> editing.

Yeah, that's always been my worry too. I could see placing the
controller-related constraints in the controller and pushing the
rest into the model though. Seems like handling all the errors across
different DBIx::Class instances and formatting them in a sane way to
the user would be difficult though (I haven't played with Rails enough
to know how exactly they handle that).

Anyone have validation logic in the model and are happy with it?

>> The other thing that's striking about the Rails approach to me
>> is the convention over configuration philosophy. I really like the
>> fact that Catalyst isn't tied to a specific view or ORM approach.
>> But OTOH, it makes the framework a bit daunting and seem less
>> organized.
> 
> 
> Some people like townhouses, some people like to architect their own house.
> Catalyst is as simple or complex as you make it.  We have normality. I
> repeat, we have normality.
> Anything you still can't cope with is therefore your own problem.

I'm not against that flexibility at all. I'm just wanting to know if
there's a generally agreed upon set of core modules to use with the
framework.

Clearly Catalyst has an opinion on how to handle the request
with Catalyst::Request. I'm sure you could override that somehow and
use your own, but it's helpful that there's a default request
interface that new developers can get up to speed quickly with.

I don't see why that can't apply to form creation and validation too.
Sure, if you don't like it, use something else, but for someone new
to Catalyst, having a Catalyst Way is helpful (unless we don't know
what a good way is).

Maurice



More information about the Catalyst mailing list