-=head1 NAME
+=head1 NAME
DBIx::Class::Manual::Joining - Manual on joining tables with DBIx::Class
Note that the '+as' does not produce an SQL 'AS' keyword in the
output, see the L<DBIx::Class::Manual::FAQ> for an explanation.
-This type of column restriction has a downside, the resulting $row
+This type of column restriction has a downside, the returned $result
object will have no 'track_name' accessor:
- while(my $row = $search_rs->next) {
- print $row->track_name; ## ERROR
+ while(my $result = $search_rs->next) {
+ print $result->track_name; ## ERROR
}
Instead C<get_column> must be used:
- while(my $row = $search_rs->next) {
- print $row->get_column('track_name'); ## WORKS
+ while(my $result = $search_rs->next) {
+ print $result->get_column('track_name'); ## WORKS
}
=head2 Incomplete related objects
output. This is better solved by storing that field in a separate
table which you only join to when needed.
-To fetch an incomplete related object, supply the dotted notation to the '+as' attribute:
+To fetch an incomplete related object, supply the dotted notation to the '+as' attribute:
$schema->resultset('CD')->search(
{ 'Title' => 'Funky CD',
},
{ join => 'tracks',
'+select' => ['tracks.Name'],
- '+as' => ['tracks.Name'],
+ '+as' => ['tracks.Name'],
order_by => ['tracks.id'],
}
);
Now you can access the result using the relationship accessor:
- while(my $row = $search_rs->next) {
- print $row->tracks->name; ## WORKS
+ while(my $result = $search_rs->next) {
+ print $result->tracks->name; ## WORKS
}
However, this will produce broken objects. If the tracks id column is
To perform joins using relations of the tables you are joining to, use
a hashref to indicate the join depth. This can theoretically go as
-deep as you like (warning: contrived examples!):
+deep as you like (warning: contrived examples!):
join => { room => { table => 'leg' } }
To join two relations at the same level, use an arrayref instead:
- join => { room => [ 'chair', 'table' ] }
+ join => { room => [ 'chair', 'table' ] }
Or combine the two: