Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to override cascade_copy when calling Row->copy #58

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/DBIx/Class.pm
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ mna: Maya

michaelr: Michael Reddick <michael.reddick@gmail.com>

mikegrb: Mike Greb <michael@thegrebs.com>

milki: Jonathan Chu <milki@rescomp.berkeley.edu>

minty: Murray Walker <perl@minty.org>
Expand Down
9 changes: 5 additions & 4 deletions lib/DBIx/Class/Row.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ sub set_inflated_columns {

=head2 copy

my $copy = $orig->copy({ change => $to, ... });
my $copy = $orig->copy({ change => $to, ... }, $dont_cascade?);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very limited (and limiting, extensibility-wise) API. I suggest a hash ref with { cascade => { rel_one => 1, rel_two => 0 } }, so you can override both ways (rels not mentioned in the cascade hash maintain the value specified in their definition) and add more options in future.


=over

Expand All @@ -1137,15 +1137,15 @@ C<< is_auto_increment => 1 >> are explicitly removed before the copy,
so that the database can insert its own autoincremented values into
the new object.

Relationships will be followed by the copy procedure B<only> if the
relationship specifies a true value for its
Unless $dont_cascade is passed, relationships will be followed by the copy
procedure B<only> if the relationship specifies a true value for its
L<cascade_copy|DBIx::Class::Relationship::Base> attribute. C<cascade_copy>
is set by default on C<has_many> relationships and unset on all others.

=cut

sub copy {
my ($self, $changes) = @_;
my ($self, $changes, $dont_cascade) = @_;
$changes ||= {};
my $col_data = { %{$self->{_column_data}} };

Expand All @@ -1163,6 +1163,7 @@ sub copy {
$new->result_source($rsrc);
$new->set_inflated_columns($changes);
$new->insert;
return $new if $dont_cascade;

# Its possible we'll have 2 relations to the same Source. We need to make
# sure we don't try to insert the same row twice else we'll violate unique
Expand Down