1 package DBIx::Class::ResultSet::Role::DQMethods;
3 use Data::Query::ExprHelpers;
8 shift->result_source->schema->storage->sql_maker->converter;
12 my ($self, $where) = @_;
13 if ($where->$_isa('Data::Query::ExprBuilder')) {
14 return $self->_apply_dq_where($where->{expr});
15 } elsif (ref($where) eq 'HASH') {
16 return $self->_apply_dq_where(
17 $self->_dq_converter->_where_to_dq($where)
20 die "Argument to ->where must be ExprBuilder or SQL::Abstract hashref, got: "
21 .(defined($where) ? $where : 'undef');
25 my ($self, $expr) = @_;
26 my ($mapped, $need_join) = $self->_remap_identifiers($expr);
27 $self->search_rs(\$mapped, (@$need_join ? { join => $need_join } : ()));
30 sub _remap_identifiers {
34 -alias => $self->current_source_alias,
35 -rsrc => $self->result_source,
38 my $attrs = $self->_resolved_attrs;
39 foreach my $j ( @{$attrs->{from}}[1 .. $#{$attrs->{from}} ] ) {
40 next unless $j->[0]{-alias};
41 next unless $j->[0]{-join_path};
43 $p = $p->{$_} ||= {} for map { keys %$_ } @{$j->[0]{-join_path}};
47 my $seen_join = { %{$attrs->{seen_join}||{}} };
48 my $storage = $self->result_source->storage;
51 my $mapped = map_dq_tree {
52 return $_ unless is_Identifier;
53 my @el = @{$_->{elements}};
56 $p = $p->{$_} ||= {} for @el;
58 my $need = my $j = {};
59 $j = $j->{$_} = {} for @el;
60 my $rsrc = $map->{''}{-rsrc};
61 $rsrc = $rsrc->related_source($_) for @el;
62 push @need_join, $need;
63 my $alias = $storage->relname_to_table_alias(
64 $el[-1], ++$seen_join->{$el[-1]}
66 $p->{''} = { -alias => $alias, -rsrc => $rsrc };
69 if ($info->{-rsrc}->has_relationship($last)) {
70 die "Invalid name on ".(join(',',@el)||'me').": $last is a relationship";
72 my $col_map = $info->{-column_mapping} ||= do {
73 my $colinfo = $info->{-rsrc}->columns_info;
74 +{ map +(($colinfo->{$_}{rename_for_dq}||$_) => $_), keys %$colinfo }
76 die "Invalid name on ".(join(',',@el)||'me').": $last"
77 unless $col_map->{$last};
78 return Identifier($info->{-alias}, $col_map->{$last});
80 return ($mapped, \@need_join);