more has_relationship_loaded tests + fix for the failing tests
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Row.pm
index 995b37b..8bdd34b 100644 (file)
@@ -118,7 +118,7 @@ with NULL as the default, and save yourself a SELECT.
 =cut
 
 ## It needs to store the new objects somewhere, and call insert on that list later when insert is called on this object. We may need an accessor for these so the user can retrieve them, if just doing ->new().
-## This only works because DBIC doesnt yet care to check whether the new_related objects have been passed all their mandatory columns
+## This only works because DBIC doesn't yet care to check whether the new_related objects have been passed all their mandatory columns
 ## When doing the later insert, we need to make sure the PKs are set.
 ## using _relationship_data in new and funky ways..
 ## check Relationship::CascadeActions and Relationship::Accessor for compat
@@ -696,6 +696,30 @@ sub has_column_loaded {
   return exists $self->{_column_data}{$column};
 }
 
+=head2 has_relationship_loaded
+
+=over 4
+
+=item Arguments: $relationship_name
+
+=item Return Value: true, if the relationship has been loaded.
+
+=back
+
+=cut
+
+sub has_relationship_loaded {
+  my ($self, $rel) = @_;
+
+  $self->throw_exception( "has_relationship_loaded needs a relationship name" )
+    unless defined $rel;
+
+  # _relationship_data gets populated from related_resultsets when the rel
+  # accessor is called
+  return exists $self->{_relationship_data}->{$rel}
+      || exists $self->{related_resultsets}->{$rel};
+}
+
 =head2 get_columns
 
   my %data = $result->get_columns;
@@ -1144,7 +1168,7 @@ sub copy {
     );
 
     my $copied = $relnames_copied->{ $rel_info->{source} } ||= {};
-    foreach my $related ($self->search_related($relname)) {
+    foreach my $related ($self->search_related($relname)->all) {
       my $id_str = join("\0", $related->id);
       next if $copied->{$id_str};
       $copied->{$id_str} = 1;