X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSet.pm;h=574b2da18f3dea55c4e8ae5d5065e472921e3ce5;hb=c97338007ede15e7c62095a642b3de382a3508bd;hp=31abf0120b95bc88d19f8a4e8b034589bd837a02;hpb=16667b3ab96a1c4a533d071e8e52eed883724828;p=dbsrgits%2FDBIx-Class.git
diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm
index 31abf01..574b2da 100644
--- a/lib/DBIx/Class/ResultSet.pm
+++ b/lib/DBIx/Class/ResultSet.pm
@@ -1756,14 +1756,19 @@ sub _rs_update_delete {
# simplify the joinmap and maybe decide if a grouping (and thus subquery) is necessary
my $relation_classifications;
if (ref($attrs->{from}) eq 'ARRAY') {
- $attrs->{from} = $storage->_prune_unused_joins ($attrs->{from}, $attrs->{select}, $cond, $attrs);
-
- $relation_classifications = $storage->_resolve_aliastypes_from_select_args (
- [ @{$attrs->{from}}[1 .. $#{$attrs->{from}}] ],
- $attrs->{select},
- $cond,
- $attrs
- ) unless $needs_group_by_subq; # we already know we need a group, no point of resolving them
+ if (@{$attrs->{from}} == 1) {
+ # not a fucking JOIN at all, quit with the dickery
+ $relation_classifications = {};
+ } else {
+ $attrs->{from} = $storage->_prune_unused_joins ($attrs->{from}, $attrs->{select}, $cond, $attrs);
+
+ $relation_classifications = $storage->_resolve_aliastypes_from_select_args (
+ [ @{$attrs->{from}}[1 .. $#{$attrs->{from}}] ],
+ $attrs->{select},
+ $cond,
+ $attrs
+ ) unless $needs_group_by_subq; # we already know we need a group, no point of resolving them
+ }
}
else {
$needs_group_by_subq ||= 1; # if {from} is unparseable assume the worst
@@ -1781,21 +1786,13 @@ sub _rs_update_delete {
) {
# Most databases do not allow aliasing of tables in UPDATE/DELETE. Thus
# a condition containing 'me' or other table prefixes will not work
- # at all. What this code tries to do (badly) is to generate a condition
- # with the qualifiers removed, by exploiting the quote mechanism of sqla
- #
- # this is atrocious and should be replaced by normal sqla introspection
- # one sunny day
- my ($sql, @bind) = do {
- my $sqla = $rsrc->storage->sql_maker;
- local $sqla->{_dequalify_idents} = 1;
- $sqla->_recurse_where($self->{cond});
- } if $self->{cond};
-
+ # at all. Tell SQLMaker to dequalify idents via a gross hack.
+ my $sqla = $rsrc->storage->sql_maker;
+ local $sqla->{_dequalify_idents} = 1;
return $rsrc->storage->$op(
$rsrc,
$op eq 'update' ? $values : (),
- $self->{cond} ? \[$sql, @bind] : (),
+ $self->{cond},
);
}
@@ -2712,6 +2709,23 @@ all in the call to C, even when set to C.
See also L and L. For information on how to declare
unique constraints, see L.
+If you need to know if an existing row was found or a new one created use
+L and L instead. Don't forget
+to call L to save the newly created row to the
+database!
+
+ my $cd = $schema->resultset('CD')->find_or_new({
+ cdid => 5,
+ artist => 'Massive Attack',
+ title => 'Mezzanine',
+ year => 2005,
+ });
+
+ if( $cd->in_storage ) {
+ # do some stuff
+ $cd->insert;
+ }
+
=cut
sub find_or_create {
@@ -2773,6 +2787,25 @@ all in the call to C, even when set to C.
See also L and L. For information on how to declare
unique constraints, see L.
+If you need to know if an existing row was updated or a new one created use
+L and L instead. Don't forget
+to call L to save the newly created row to the
+database!
+
+ my $cd = $schema->resultset('CD')->update_or_new(
+ {
+ artist => 'Massive Attack',
+ title => 'Mezzanine',
+ year => 1998,
+ },
+ { key => 'cd_artist_title' }
+ );
+
+ if( $cd->in_storage ) {
+ # do some stuff
+ $cd->insert;
+ }
+
=cut
sub update_or_create {
@@ -3062,9 +3095,9 @@ source alias of the current result set:
my $me = $self->current_source_alias;
- return $self->search(
+ return $self->search({
"$me.modified" => $user->id,
- );
+ });
}
=cut
@@ -3446,7 +3479,6 @@ sub _resolved_attrs {
$attrs->{_collapse_order_by} = \@$prefetch_ordering;
}
-
# if both page and offset are specified, produce a combined offset
# even though it doesn't make much sense, this is what pre 081xx has
# been doing
@@ -4195,6 +4227,24 @@ rows per page if the page attribute or method is used.
Specifies the (zero-based) row number for the first row to be returned, or the
of the first row of the first page if paging is used.
+=head2 software_limit
+
+=over 4
+
+=item Value: (0 | 1)
+
+=back
+
+When combined with L and/or L the generated SQL will not
+include any limit dialect stanzas. Instead the entire result will be selected
+as if no limits were specified, and DBIC will perform the limit locally, by
+artificially advancing and finishing the resulting L.
+
+This is the recommended way of performing resultset limiting when no sane RDBMS
+implementation is available (e.g.
+L using the
+L hack)
+
=head2 group_by
=over 4