From e951858e3c499abf50e7bbe7e1d4e57460825511 Mon Sep 17 00:00:00 2001 From: Jess Robinson Date: Mon, 2 Jun 2008 18:46:12 +0000 Subject: [PATCH 1/3] I suck, should read code while doccing it, not assume someone else got it right! --- lib/DBIx/Class/Relationship.pm | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/DBIx/Class/Relationship.pm b/lib/DBIx/Class/Relationship.pm index d159cc490..39c0d1220 100644 --- a/lib/DBIx/Class/Relationship.pm +++ b/lib/DBIx/Class/Relationship.pm @@ -222,12 +222,13 @@ methods and valid relationship attributes. =back -Creates a one-to-many relationship, where the corresponding elements of the -foreign class store the calling class's primary key in one (or more) of its -columns. This relationship defaults to using C<$accessor_name> as the foreign -key in C<$related_class> to resolve the join, unless C<$foreign_key_column> -specifies the foreign key column in C<$related_class> or C specifies a -reference to a join condition hash. +Creates a one-to-many relationship, where the corresponding elements +of the foreign class store the calling class's primary key in one (or +more) of its columns. This relationship defaults to using the end of +this classes namespace as the foreign key in C<$related_class> to +resolve the join, unless C<$foreign_key_column> specifies the foreign +key column in C<$related_class> or C specifies a reference to a +join condition hash. =over @@ -273,25 +274,27 @@ OR condition. =back # in an Author class (where Author has_many Books) + # assuming related class is storing our PK in "author_id" My::DBIC::Schema::Author->has_many( books => 'My::DBIC::Schema::Book', 'author_id' ); - # OR (same result, assuming related_class is storing our PK) + # OR (same result) My::DBIC::Schema::Author->has_many( books => 'My::DBIC::Schema::Book', + { 'foreign.author_id' => 'self.id' }, ); - - # OR (same result) + + # OR (similar result, assuming related_class is storing our PK, in "author") + # (the "author" is guessed at from "Author" in the class namespace) My::DBIC::Schema::Author->has_many( books => 'My::DBIC::Schema::Book', - { 'foreign.author_id' => 'self.id' }, ); - + # Usage # resultset of Books belonging to author From a7e65bb51bb6dbdfdaf229a6d0dd1d8c25bef337 Mon Sep 17 00:00:00 2001 From: Ash Berlin Date: Tue, 3 Jun 2008 16:11:25 +0000 Subject: [PATCH 2/3] Remove the length limit on identifiers - it doesn't belong in DBIx::Class A few doc fixes --- lib/DBIx/Class/ResultSet.pm | 22 +++++++-- lib/SQL/Translator/Parser/DBIx/Class.pm | 35 ++------------ t/71mysql.t | 5 +- t/86sqlt.t | 55 +-------------------- t/lib/DBICTest/Schema.pm | 4 +- t/lib/DBICTest/Schema/LongColumns.pm | 64 ------------------------- 6 files changed, 27 insertions(+), 158 deletions(-) delete mode 100644 t/lib/DBICTest/Schema/LongColumns.pm diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index e113fdb67..af97ebb76 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -2435,13 +2435,27 @@ C or C relationships, which saves us two SQL statements in this case. Simple prefetches will be joined automatically, so there is no need -for a C attribute in the above search. If you're prefetching to -depth (e.g. { cd => { artist => 'label' } or similar), you'll need to -specify the join as well. +for a C attribute in the above search. C can be used with the following relationship types: C, C (or if you're using C, any relationship declared -with an accessor type of 'single' or 'filter'). +with an accessor type of 'single' or 'filter'). A more complex example that +prefetches an artists cds, the tracks on those cds, and the tags associted +with that artist is given below (assuming many-to-many from artists to tags): + + my $rs = $schema->resultset('Artist')->search( + undef, + { + prefetch => [ + { cds => 'tracks' }, + { artist_tags => 'tags' } + ] + } + ); + + +B If you specify a C attribute, the C and C