[Catalyst] Instant CRUD with DBIC::Schema

Zbigniew Lukasiak zzbbyy at gmail.com
Wed Mar 12 16:11:30 GMT 2008


On Wed, Mar 12, 2008 at 4:27 PM, Zbigniew Lukasiak <zzbbyy at gmail.com> wrote:
> On Wed, Mar 12, 2008 at 4:12 PM, Peter Karman <peter at peknet.com> wrote:
>  >
>  >
>  >  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?
>
>  OK - so that was just a misunderstanding - I thought we were still
>  talking about the CRUD methods.
>
>
>  >
>  >
>  >
>  >  >
>  >  >>      $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.
>
>  If you'd make them to use the same db connection than indeed this
>  would be like the ModelAdaptor. But then again you should have just on
>  adaptor per model type - not per table (for models with tables).

That should be: just one adaptor class per model type (class).


>
>
>  >
>  >  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.
>
>  Yeah - I would consider the objects on the stash as part of the
>  interface so they should be the original ORM objects.
>
>
>  >
>  >  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/
>  >
>  >
>  >  _______________________________________________
>  >  List: Catalyst at lists.scsys.co.uk
>  >  Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>  >  Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>  >  Dev site: http://dev.catalyst.perl.org/
>  >
>
>
>
>
>
> --
>  Zbigniew Lukasiak
>  http://brudnopis.blogspot.com/
>



-- 
Zbigniew Lukasiak
http://brudnopis.blogspot.com/



More information about the Catalyst mailing list