# Add the ResultSet's alias
foreach my $key (grep { ! m/\./ } keys %$unique_query) {
- $unique_query->{"$self->{attrs}->{alias}.$key"} = delete $unique_query->{$key};
+ my $alias = ($self->{attrs}->{_live_join}) ? $self->{attrs}->{_live_join} : $self->{attrs}->{alias};
+ $unique_query->{"$alias.$key"} = delete $unique_query->{$key};
}
push @unique_queries, $unique_query;
my $collapsed = $self->_collapse_query($query);
+ my $alias = ($self->{attrs}->{_live_join}) ? $self->{attrs}->{_live_join} : $self->{attrs}->{alias};
foreach my $name ($self->result_source->unique_constraint_names) {
- my @unique_cols = map { "$self->{attrs}->{alias}.$_" }
+ my @unique_cols = map { "$alias.$_" }
$self->result_source->unique_constraint_columns($name);
# Count the values for each unique column
foreach my $key (keys %$collapsed) {
my $aliased = $key;
- $aliased = "$self->{attrs}->{alias}.$key" unless $key =~ /\./;
+ $aliased = "$alias.$key" unless $key =~ /\./;
next unless exists $seen{$aliased}; # Additional constraints are okay
$seen{$aliased} = scalar @{ $collapsed->{$key} };
}
}
}
-
+ if ($is_prefetch) {
+ my $final_array = [];
+ foreach my $element (@{$array}) {
+ push(@{$final_array}, $element) unless (exists $hash->{$element});
+ }
+ $array = $final_array;
+ }
if ((keys %{$hash}) && (scalar(@{$array} > 0))) {
return [$hash, @{$array}];
} else {
my $schema = DBICTest->init_schema();
-plan tests => 6;
+plan tests => 8;
my @rs1a_results = $schema->resultset("Artist")->search_related('cds', {title => 'Forkful of bees'}, {order_by => 'title'});
is($rs1a_results[0]->title, 'Forkful of bees', "bare field conditions okay after search related");
# this is wrong, should accept me.title really
my $rs3 = $rs2->search_related('cds')->search({'cds.title' => 'Forkful of bees'});
-cmp_ok($rs3->count, '==', 3, "Three artists returned");
+cmp_ok($rs3->count, '==', 1, "Three artists returned");
my $rs4 = $schema->resultset("CD")->search({ 'artist.artistid' => '1' }, { join => ['tracks', 'artist'], prefetch => 'artist' });
my @rs4_results = $rs4->all;
my $rs5 = $rs4->search({'tracks.title' => 'Sticky Honey'});
is($rs5->count, 1, "search without using previous joins okay");
+my $record_rs = $schema->resultset("Artist")->search(undef, { join => 'cds' })->search(undef, { prefetch => { 'cds' => 'tracks' }});
+my $record_jp = $record_rs->next;
+ok($record_jp, "prefetch on same rel okay");
+
+my $cd = $schema->resultset("CD")->find(1);
+my $producers = $cd->producers;
+is($producers->find(2)->name, 'Bob The Builder', "find on many to many okay");
+
1;