DBIx::Class::Result::ProxyField - Component Result::ProxyField is a component for DBIx::Class object which permit to defined public name for each column object
Version 0.03
First, this module would evolve, it is not completly finished
To use Result::ProxyField component, you need to declare it in Result and ResultSet of your DBIx::Class object
in your Result :
package App::Schema::Result::Object; # declare columns : for each column you want use an other name, declare public_name __PACKAGE__->add_columns( "superobjectid", { data_type => "integer", is_nullable => 1, public_name => 'super_object_id' }, "actif", { data_type => "tinyint", default_value => 1, is_nullable => 1 }, "creation_datetime", { data_type => "datetime", is_nullable => 1, public_name => 'created_at'} ); # after declare columns you can initialise the Result::ProxyField component __PACKAGE__->load_component(qw/Result::ProxyField/); __PACKAGE__->init_proxy_field();
in your ResultSet
package App::Schema::ResultSet::Object; use base 'DBIx::Class::ResultSet::ProxyField';
On your code, you can use public_name to set or get column
my $schema = App::Schema->connect('dbi:SQLite:db/example.db'); my @objects = $schema->resultset('Object')->search({created_at => {"==", undef},super_object_id => 1}); # is the same than my @objects = $schema->resultset('Object')->search({creation_datetime => {"==", undef}, superobjectid => 1}); my $object = $objects[0]; $object->created_at(DateTime.now()); #is the same than $object->creation_datetime(DateTime.now()); my $created_at = $object->created_at; #is the same than my $created_at = $object->creation_datetime; ...etc
becareful, the relationship id stay superobjectid
$rh_ext_to_bdd store mapping table from public to database by class
$rh_bdd_to_ext store mapping table from database to public by class
Class function
Accessor to mapping table from public to database for a class
Accessor to mapping table from database to public for a class
Init function which defined accessor from class definition
Instance function
set public accessor from database accessor
sub adaptator_to_ext { my $self = shift; my $class = ref $self; foreach my $key_bdd (keys %{$rh_bdd_to_ext->{$class}}) { my $key_ext = $rh_bdd_to_ext->{$class}->{$key_bdd}; $self->$key_ext( $self->$key_bdd ); } }
set database accessor from public accessor
sub adaptator_to_bdd { my $self = shift; my $class = ref $self; foreach my $key_ext (keys %{$rh_ext_to_bdd->{$class}}) { # $key = champ bdd my $key_bdd = $rh_ext_to_bdd->{$class}->{$key_ext}; $self->$key_bdd( $self->$key_ext ) if defined $self->$key_ext; } }
format hash columns data of object with public accessor
re defined columns_data function to component Result::DataColumns
return only column data Hash with public name
re defined update to adapt object field before update
re defined insert to adapt object field before insert
re defined delete to adapt object field before delete
Nicolas Oudard, nicolas@oudard.org
nicolas@oudard.org
Please report any bugs or feature requests to bug-dbix-class-result-proxyfield at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBIx-Class-Result-ProxyField. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-dbix-class-result-proxyfield at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc DBIx::Class::Result::ProxyField
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=DBIx-Class-Result-ProxyField
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/DBIx-Class-Result-ProxyField
CPAN Ratings
http://cpanratings.perl.org/d/DBIx-Class-Result-ProxyField
Search CPAN
http://search.cpan.org/dist/DBIx-Class-Result-ProxyField/
Copyright 2010 Nicolas Oudard.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install DBIx::Class::Result::ProxyField, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Class::Result::ProxyField
CPAN shell
perl -MCPAN -e shell install DBIx::Class::Result::ProxyField
For more information on module installation, please visit the detailed CPAN module installation guide.