* On Mon, Feb 23 2009, Alexander Tamm wrote: > Hi, > > I'm still a bit confused about how models using DBIx::Class should > work in a catalyst application. > > Is it the case that classes placed in the Model-directory will somehow > (magically?) let me have objects inflated as instances of the class > using a similarly named Schema? > > For example, I have this class: > > package TestApp::Model::Foo::User; > > use strict; > sub full_name { > my ( $self ) = @_; > return $self->first_name() . q{ } . $self->last_name(); > } > 1; > > Objects created by $c->model('Foo::User') *will* work. Ie. they have > the methods full_name(), first_name() and last_name(). > > It looks a bit weird to me, but it seems to work. Should it work?
You shouldn't do this (*), it is very confusing. Put functions like this in the row class, i.e. YourApp::Schema::Foo::User, so that all users of the schema have access to these methods. Catalyst::Model::DBIC::Schema just proxies each class so that $c->model('Schema::Foo') == $c->model('Schema')->resultset('Foo'). That's all you should use it for. (*) BTW, the behavior you described does work intentionally, for cases when you need the objects in Catalyst to be different than with plain DBIC. I think it's a bad idea to use this "feature" except in very special cases -- of which "full_name" is not one. Regards, Jonathan Rockway -- print just => another => perl => hacker => if $,=$" _______________________________________________ List: Catalyst@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/