DBIx-Class-Result-ExternalAttribute

 view release on metacpan or  search on metacpan

lib/DBIx/Class/Result/ExternalAttribute.pm  view on Meta::CPAN


=head2 columns_data_with_attribute

columns_data_with_external_attribute is deprecated, please use get_column_data_with_attribute

=cut

sub columns_data_with_attribute {
    carp "columns_data_with_external_attribute is deprecated, please use get_column_data_with_attribute";
    my $self = shift;
    $self->get_column_data_with_attribute(@_);
}

=head2 get_column_data_with_attribute

extract column_data with attribute column

=cut

sub get_column_data_with_attribute {
    my $self      = shift;
    my $klass     = ref $self;
    my $rh_result = $self->get_column_data();
    foreach my $rel_attr ( keys %{ $klass->rh_klass_attribute_column } ) {
        my $rel_object = $self->$rel_attr;
        next unless defined $rel_object;
        my $rh_result_attribute = $self->$rel_attr->get_column_data();
        foreach my $col ( @{ $klass->rh_klass_attribute_column($rel_attr)->{'columns'} } ) {
            $rh_result->{$col} = $rh_result_attribute->{$col};
        }
    }

    return $rh_result;
}

=head2 prepare_params_with_attribute

prepare params for creation with attributes

=cut

sub prepare_params_with_attribute {
    my ( $klass, $rh_fields ) = @_;
    foreach my $rel ( keys %{ $klass->rh_klass_attribute_column } ) {
        foreach my $col ( @{ $klass->rh_klass_attribute_column($rel)->{'columns'} } ) {
            if ( defined $rh_fields->{$col} ) {
                $rh_fields->{$rel}->{$col} = $rh_fields->{$col};
                delete $rh_fields->{$col};
            }
        }
    }
    return $rh_fields;
}

=head2 update

overdefinition of update function

=cut

sub update {
    my ( $self, $rh_fields ) = @_;
    my $klass = ref $self;
    foreach my $rel ( keys %{ $klass->rh_klass_attribute_column } ) {
        foreach my $col ( @{ $klass->rh_klass_attribute_column($rel)->{'columns'} } ) {
            if ( defined $rh_fields->{$col} ) {
                $self->$rel->$col( $rh_fields->{$col} );
                delete $rh_fields->{$col};
            }
        }
    }
    return $self->next::method($rh_fields);
}

=head2 insert

overdefinition of update function

=cut
sub insert 
{
    my ( $self, @args ) = @_;
    my $klass = ref $self;
    $self->next::method(@args);
    foreach my $rel ( keys %{ $klass->rh_klass_attribute_column } ) {
        $self->find_or_create_related($rel, {});
    }
    return $self;
}

=head1 AUTHOR

Nicolas Oudard, C<< <nicolas at oudard.org> >>

=head1 BUGS

Please report any bugs or feature requests to C<bug-dbix-class-result-externalattribute at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBIx-Class-Result-ExternalAttribute>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.




=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc DBIx::Class::Result::ExternalAttribute


You can also look for information at:

=over 4

=item * RT: CPAN's request tracker

L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=DBIx-Class-Result-ExternalAttribute>

=item * AnnoCPAN: Annotated CPAN documentation

L<http://annocpan.org/dist/DBIx-Class-Result-ExternalAttribute>



( run in 2.383 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )