On Sat, 11 Nov 2006, Josef Karthauser wrote:

On Sat, Nov 11, 2006 at 01:17:17AM +0000, Josef Karthauser wrote:
        my $rs = $c->model('Contact')->
            search($criteria,
                { page => $page, rows => 10,
                  order_by => [$order_by, $default_order, "domains.domainname"],
#1                prefetch => { 'domains' }
#2                prefetch => { 'domains' =>
#2                  { 'self.contactid' => 'foreign.registrant',
#2                    'self.owner' => 'foreign.owner' }}
                });

Neither of #1 or #2 appear to do what I want.  I get 'No such
relationship' whenever I try and process the request.


Ahha, got it.

What I wanted was:
   my $rs = $c->model('Contact')->
        search($criteria,
           { page => $page, rows => 10,
                order_by => [$order_by, $default_order, "domains.domainname"],
                prefetch => 'domains'
            }
        });

This now works, as the relationships are correctly described in the
class files.  However I would have thought that #2 should have
worked too; I'd appreciate some understanding on that count.  The
self. and foreign. functionality I don't think is clearly deliniated
in the documentation.  (For instance when I read that I assumed
that I needed to replace self with the local table name and foreign
with the foreign table name, but that didn't work).

Hi Joe,

From the docs:


The condition needs to be an SQL::Abstract-style representation of the join between the tables. When resolving the condition for use in a "JOIN", keys using the pseudo-table "foreign" are resolved to mean "the Table on the other side of the relationship", and values using the pseudo-table "self" are resolved to mean "the Table this class is rep- resenting".

.. How would you write this so that it makes sense to you? We're always on the lookout for parts of the docs people don't understand.. Please give us some input to help improve them.

Jess


_______________________________________________
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