Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^2: list DBIX::Class many_to_many relations

by misterb101 (Sexton)
on Dec 22, 2010 at 16:03 UTC ( [id://878577]=note: print w/replies, xml ) Need Help??

in reply to Re: list DBIX::Class many_to_many relations
in thread list DBIX::Class many_to_many relations

Hi there, Thanks a lot for you answer! Although it did not exactly answer my question it taught me a LOT about DBIC that I did not know yet. Thanks for that! What I was actually looking for was fetching all many_to_many related objects without exactly knowing the names of the relations. I have solved it by doing:
my @related_models; # fetch relations from model. By doing it this way when new many_t +o_many relations are created, the controller automatically picks them + up my @relations = $self->schema->source('Document')->relationships() +; foreach (@relations) { if ($_ =~ m/(^.*)_documents$/) { push @related_models, $1; } } foreach (@related_models) { my ($relObj) = $object->$_(); #Assume only one object refe +rs to this one (business logic) if ($relObj) { $row{relatedObject} = $relObj->name(); $row{relatedObjectId} = $relObj->id(); $row{relatedObjectType} = $relObj->_source_handle->sou +rce_moniker; # Why is getting the source Name so difficult? } } push @data, \%row; } Again thanks for the very informative reply!

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://878577]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-06-25 19:51 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.