Good morning,

On 2/01/10 at 12:36 AM -0600, Pavel O. Karoukin <[email protected]> wrote:

Yeah, this work for one record as my example above, but I want to get more
"generic" aproach. For example how to code schema join for the following
query:

SELECT * FROM
things as t1
JOIN
things as t2
ON
t1.type <> t2.type
AND
t1.uid  <> t2.uid

Create a self-join relationship (other_things in my previous example)

__PACKAGE__->has_many(other_things => 'MyApp::Schema::Result::Things', 'thing_id');


If I will be able to make it joined this way then I will be able to apply
any conditions later and not write custom accessor each time.

Since the custom method returns a resultset, you can continue to chain other criteria from it:

my $things = 
$schema->resultset("Thing")->first->different_things->search({other_cond=>'type2'});

I think you might be stuck on what relationships are in DBIC; they are really just very fancy glue for returning resultsets; you can also compose and return your own resultsets. Write methods that take different arguments which allow you to compose the desired results. Eg. the example method I gave allows the 'type' to be passed as an argument or taken from the current record as a default.

Anything you are wanting to define in the %attr for relationships can also be defined in your custom method. There is some fancy glue you don't get (eg. add_to_* methods), but for doing different queries the technique works a treat.

Charlie

--
   Ꮚ Charlie Garrison ♊ <[email protected]>
   〠 PO Box 141, Windsor, NSW 2756, Australia

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
http://www.ietf.org/rfc/rfc1855.txt

_______________________________________________
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/[email protected]

Reply via email to