[Dbix-class] Question about belongs_to

Jason Kohles email at jasonkohles.com
Fri Dec 30 18:02:23 CET 2005


On 12/30/05, Jon Molin <jon.molin at gmail.com> 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'})
>
> 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?
>
> If I'm understanding the question correctly, I think what you are looking
for is:
__PACKAGE__->belongs_to('author', 'MyApp::DBIC::Author', 'authID');

--
Jason Kohles
email at jasonkohles.com - http://www.jasonkohles.com/
"A witty saying proves nothing."  -- Voltaire
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/dbix-class/attachments/20051230/401437f0/attachment.htm


More information about the Dbix-class mailing list