[Dbix-class] get $author from a row $author->books->first

Byron Young Byron.Young at riverbed.com
Fri Apr 25 19:25:43 BST 2008


Moritz Onken wrote on 2008-04-25:
>
> Am 25.04.2008 um 17:00 schrieb Matt S Trout:
>
>> On Fri, Apr 25, 2008 at 01:56:38PM +0200, Moritz Onken wrote:
>>> Hi,
>>>
>>> I want to add a new method to my Book class. This methods needs to
>>> call a relationship of $author. So how do I get the $author object if
>>> I am calling a function in the Book class. I get the row object by
>>> calling $book = $author->books->first (or similar).
>>>
>>> I read the docs but couldn't anything but
>>>
>>>      my $schema = $self->result_source->schema;
>>>
>>> Which gives me the schema itself but not the $author object.
>>
>> $self->author
>  And if $self->author is a has_many or many_many relationship will it
> still return the one author only and not all that relate to the book?
>
> moritz
>

Hey Moritz,

Any methods you add in your Book schema class will be methods that act on a book row object ($self will be a row object).  Doing that is described here (but only wrt overloading methods, but the idea is the same for new methods) http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/Manual/Cookbook.pod#OVERLOADING_METHODS

Hope that helps.  Not sure if that's what you were asking about, though.  Your question is a little vague.

Regards,
Byron





More information about the DBIx-Class mailing list