[Dbix-class] joining on NULL fields

Ian Sillitoe ian at sillit.com
Mon Mar 17 20:02:42 GMT 2008


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 =3D> 'd1' },
 {
   join     =3D> [ qw/ domain_to_classification_depth_(1-4) / ],
   prefetch =3D> [ 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" =3D> "self.depth_1",
    "foreign.depth_2" =3D> "self.depth_2",
    "foreign.depth_3" =3D> "self.depth_3",
    "foreign.depth_4" =3D> "self.depth_4",
  },
);

[WORKS]

MySchema::Domain->belongs_to(
  "domain_to_classification_depth_2",
  "MySchema::Classification",
  {
    "foreign.depth_1" =3D> "self.depth_1",
    "foreign.depth_2" =3D> "self.depth_2",
    "foreign.depth_3" =3D> \"NULL",
    "foreign.depth_4" =3D> \"NULL",
  },
);

[ERROR]

Invalid rel cond val NULL at
/opt/perl-5.8.8/lib/site_perl/5.8.8/DBIx/Class/Schema.pm
line 954

I've looked at the entry on DBIx::Manual::FAQ ("define a foreign key
relationship where the key field may contain NULL?". However I don't think
this quite answers my question as the table I'm joining from doesn't have
any NULL values - I just want to join to a specific row in table B where
some of those values are NULL.

Cheers,

Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20080317/25b=
23870/attachment.htm


More information about the DBIx-Class mailing list