[Dbix-class] Re: Join Myself?

2012-07-09 Thread xli
From the manual; can you duplicate the '-ident' condition in the
example to get what you're after?

http://search.cpan.org/~arodland/DBIx-Class-0.08196/lib/DBIx/Class/Relationship/Base.pm

To specify joins which describe more than a simple equality of column
values, the custom join condition coderef syntax can be used. For
example:

  My::Schema::Artist-has_many(
cds_80s = 'My::Schema::CD',
sub {
  my $args = shift;

  return {
$args-{foreign_alias}.artist = { -ident =
$args-{self_alias}.artistid },
$args-{foreign_alias}.year   = { '', 1979, '', 1990 },
  };
}
  );

  ...

  $artist_rs-search_related('cds_80s')-next;

will result in the JOIN clause:

  ... FROM artist me LEFT JOIN cd cds_80s ON
cds_80s.artist = me.artistid
AND cds_80s.year  ?
AND cds_80s.year  ?

___
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk


[Dbix-class] Re: Join Myself?

2012-07-07 Thread Steve Wells
On Fri, Jul 6, 2012 at 11:33 AM, Steve Wells we...@cedarnet.org wrote:
 I'm trying to convert this SQL statement to DBIC and I'm failing miserably.

Let me clarify a bit…

Given this setup:

http://stackoverflow.com/questions/1313120/retrieving-the-last-record-in-each-group

it is possible to convert the SQL statement:

SELECT m1.*
FROM messages m1 LEFT JOIN messages m2
 ON (m1.name = m2.name AND m1.id  m2.id)
WHERE m2.id IS NULL;

to DBIx::Class.

I have read the manual / tutorials etc but it doesn't seem possible to
add and extras (i.e. m1.id  m2.id) to your join command.

Is this true?

___
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk