[Dbix-class] Question about belongs_to

Matt S Trout dbix-class at trout.me.uk
Fri Dec 30 18:10:10 CET 2005


On Fri, Dec 30, 2005 at 03:25:16PM +0100, Jon Molin wrote:
> Hi list,
> 
> I tried the "Many-to-many relationships" example from the cookbok. It works
> fine but I can't figure out how to name the belongs_to relation other than
> the name of the column. That is:
> 
> __PACKAGE__->belongs_to('authID' => 'MyApp::DBIC::Author');
> 
> If I want to access the author by doing $obj->author, rather than
> $obj->authID. I've tried:
> __PACKAGE__->belongs_to ('author' => 'MyApp::DBIC::Author', undef,
> 'authID');# (have also tried with {'foreign.authID' => 'self.authID'})

Drop that undef - it's conditional *then* attrs; you give undef if you want
the automatic conditional but to customise the attrs.
 
> But that just gives me a complaint saying there is no author method in
> MyApp::DBIC::Book2Author. This confuses me as there is no problem naming
> has_many relations. Is it not possible or do I call the belongs_to method
> completely wrong?

-- 
     Matt S Trout       Offering custom development, consultancy and support
  Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

 + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Dbix-class mailing list