[Dbix-class] accessing ResultSet function from a related object

John Goulah jgoulah at gmail.com
Thu Jul 5 02:44:48 GMT 2007


On 7/4/07, Matt S Trout <dbix-class at trout.me.uk> wrote:
>
> On Wed, Jul 04, 2007 at 05:47:05PM -0400, John Goulah wrote:
> > I am having some trouble in both controller and template code accessing
> > resultset functions off of chained/related objects (because from what
> I'm
> > seeing they are not ResultSets but of the type
> > MyApp::Model::MyAppDB::Tablename).
>
> That's isa MyAppDB::Tablename, not MyAppDB::TablenameResultset or
> whatever.
>
> > For example I can create a ResultSet object directly like:
> >    my $owner =3D $c->model('MyDB::User')->search({ user_id =3D> $owner_=
id }
> );
> >
> > and then I can do for example:
> >
> >    $owner->some_result_set_method()
>
> If it's an RS, call the variable $owners or $owner_rs. Trust me that this
> will
> make your life easier.
>
> > but I can't do this if I want to chain off another object, such as:
> >
> >    #not ok
> >    my $owner_id =3D
> > $photo_details_rs->first()->owner->some_result_set_method();
> >
> > but...
> >
> >    #this is fine, just accessing a field
> >    my $owner_id =3D $photo_details_rs->first()->owner->user_id;
>
> The relationship must be returning an object, not a resultset then.
>
> Don't confuse the Result (single object) and ResultSet (effectively a
> virtual collection) objects. There's no reason you can't implement methods
> on both but they are -not- the same thing.



Oh that makes sense, I am just putting the method in the wrong place-

Thanks!
John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20070704/90e=
c954b/attachment.htm


More information about the Dbix-class mailing list