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, { 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;
50 my $mapped = map_dq_tree {
51 return $_ unless is_Identifier;
52 my @el = @{$_->{elements}};
55 $p = $p->{$_} ||= {} for @el;
57 my $need = my $j = {};
58 $j = $j->{$_} = {} for @el;
59 my $rsrc = $map->{''}{-rsrc};
60 $rsrc = $rsrc->related_source($_) for @el;
61 push @need_join, $need;
62 my $alias = $storage->relname_to_table_alias(
63 $el[-1], ++$seen_join->{$el[-1]}
65 $p->{''} = { -alias => $alias, -rsrc => $rsrc };
68 my $col_map = $info->{-column_mapping} ||= do {
69 my $colinfo = $info->{-rsrc}->columns_info;
70 +{ map +(($colinfo->{$_}{rename_for_dq}||$_) => $_), keys %$colinfo }
72 die "Invalid name on ".(join(',',@el)||'me').": $last"
73 unless $col_map->{$last};
74 return Identifier($info->{-alias}, $col_map->{$last});
76 return ($mapped, \@need_join);