[Catalyst] Instant CRUD with DBIC::Schema

Peter Karman peter at peknet.com
Wed Mar 12 15:12:32 GMT 2008



On 03/12/2008 09:44 AM, Zbigniew Lukasiak wrote:

>>  So we'd have:
>>
>>   sub thing : Local {
>>      my ($self, $c, $id) = @_;
>>      my $thing = $c->model('Foo')->fetch( id => $id );
> 
> my $thing = $self->model_adaptor->fetch( id => $id );
> 
> The model adaptor should know the model it is using (and in the case
> of DBIC also the table )

In my example, $self is not a CX::CRUD::Controller. Just a plain ol' Catalyst::Controller.
Why must it implement a model_adaptor method then?


> 
>>      $c->stash->{object} = $thing;  # NOT a CX::CRUD::Object
>>   }
>>
>>  and if wanted to update $thing:
>>
>>      $c->model('Foo')->update( $thing );
> 
> $self->model_adaptor->update( $thing );
> 
>>  I could live with that. Does it meet your needs? Does it make it easier to implement a
>>  DBIC model and FormFu controller?
>>
> 
> Yes.  In general - my point is that let's do the wrapping only for the
> CRUD methods that need them.  Let's not force the user to use the CRUD
> wrappers as their models.
> 

Users of CX::CRUD Models or Controllers don't have to use both together. It's just easier
if they do. And CX::CRUD doesn't force you to only use its models.

You could have:

 lib/MyApp/Model/Foo.pm     # not a CX::CRUD::Model. Just a DBIC::Schema model.
 lib/MyApp/Model/FooCRUD.pm # is a CX::CRUD::Model::DBIC

MyApp::Model::FooCRUD can act like your ModelAdaptor. By adding yet another kind of thing,
a model adaptor, into the mix, that feels more complex to me rather than less.

I think I'm agreeing with you that the CX::CRUD API could be simplified, that the ::Object
class could go away, and that the Model class could take over the c/r/u/d methods that
Object currently performs.

If you like the model_adaptor() syntax in the Controller API, how would you implement a
ModelAdaptor class and how would you change the Controller API to use it?

-- 
Peter Karman  .  peter at peknet.com  .  http://peknet.com/




More information about the Catalyst mailing list