[Dbix-class] joining on NULL fields
Matt S Trout
dbix-class at trout.me.uk
Sun Apr 6 17:58:28 BST 2008
On Mon, Mar 17, 2008 at 08:02:42PM +0000, Ian Sillitoe wrote:
> There might be a really simple answer to this, but I'm afraid I can't see it
> - I would really appreciate any help.
>
> I'm trying to describe a number of relationships between two tables that
> require 0 or more conditions on the join to be NULL - e.g.
>
> MySchema->('Domain')->search(
> { domain_id => 'd1' },
> {
> join => [ qw/ domain_to_classification_depth_(1-4) / ],
> prefetch => [ qw/ domain_to_classification_depth_(1-4) / ]
> }
> )
>
> Where the relationships are defined as:
>
> MySchema::Domain->belongs_to(
> "domain_to_classification_depth_4",
> "MySchema::Classification",
> {
> "foreign.depth_1" => "self.depth_1",
> "foreign.depth_2" => "self.depth_2",
> "foreign.depth_3" => "self.depth_3",
> "foreign.depth_4" => "self.depth_4",
> },
> );
>
> [WORKS]
>
> MySchema::Domain->belongs_to(
> "domain_to_classification_depth_2",
> "MySchema::Classification",
> {
> "foreign.depth_1" => "self.depth_1",
> "foreign.depth_2" => "self.depth_2",
> "foreign.depth_3" => \"NULL",
> "foreign.depth_4" => \"NULL",
> },
> );
There's not currently a way to do that without using a custom from => attr
to your resultset.
Proposed syntax + patches welcome :)
--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/
More information about the DBIx-Class
mailing list