[Dbix-class] Announcing the trial run towards 0.08200

Peter Rabbitson rabbit+dbic at rabbit.us
Tue Jan 25 09:42:48 GMT 2011


Hi there. Last night DBIx-Class-0.08190-TRIAL made its way to CPAN. It is
identical to 0.08127 except for the fact it supports a long anticipated
feature: completely arbitrary relationship conditions are finally here!

You may be wondering what is the -TRIAL all about (and why you can not
cpan DBIx::Class this release): well, we do not want to take chances of
breaking your existing code. While the dev team is pretty confident about
the implementation of this feature, we also recognize that there is a lot
of code out there on the DarkPAN which utilizes various hacks to get
around the lack of this very same feature. As such 0.08190 marks the
start of a month-long trial period to allow sufficient testing for all
interested in upgrading. So please *please* *PLEASE* do test this release
and let us know of any and all problems you may encounter. We especially
need feedback from folks using custom {from} attributes in their search()
calls - there is a small but notable chance that we did not anticipate all
possible use-cases, and that the compatibility shims need tweaking.

You can install this release in a flash via the wonderful cpanminus[1].
Once again keep in mind that aside from the extra functionality, this
release is identical to the official 0.08127 (which one must add turned
out to be surprisingly bug-lean :)

Baring any glaring issues (or in the case of utter lack of feedback)
DBIC 0.08200 will ship about a month from now during the last week of
February.


So what is this all about anyway? Now in addition to the simple "column
equality" join conditions, you can declare your relationships this way:


   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" },
       };
     }
   );

Which declares a regular relationship which can be used as usual e.g.

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

which in turn yields the SQL:

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

with bind values of 1990 and 1979

There is excellent documentation[2] so please take time to read it. In
addition take a peek at the test suite[3] which shows some unusual tricks
possible with custom join conditions.

You may also be wondering if this work is complete - the answer is yes
and no. The API for the coderefs is stable and will not change, nor will
the add_relationship implementation. However we feel that this is not
sufficient for a complete EAV extravaganza, so a method to pass arguments
to the coderef via search() is currently in the works. This should make
the custom relationships first class citizens, by allowing one to define
the relationship partially on startup, and fill in the necessary binds
during runtime on individual search() basis.

So once again - please test and let us know!

Happy search()ing :)

[1] curl -L http://cpanmin.us | perl - http://search.cpan.org/CPAN/authors/id/R/RI/RIBASUSHI/DBIx-Class-0.08190-TRIAL.tar.gz
[2] http://search.cpan.org/~ribasushi/DBIx-Class-0.08190-TRIAL/lib/DBIx/Class/Relationship/Base.pm#condition
[3] http://github.com/dbsrgits/dbix-class/commit/cacb39bb152f82ea2684c526c41be6caf3ab6679#diff-14




More information about the DBIx-Class mailing list