On 7/4/07, Matt S Trout <[EMAIL PROTECTED]> 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 = $c->model('MyDB::User')->search({ user_id => $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 =
> $photo_details_rs->first()->owner->some_result_set_method();
>
> but...
>
>    #this is fine, just accessing a field
>    my $owner_id = $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
_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to