Persistence::Relationship::ToOne - To one relationship
use Persistence::Relationship::ToOne ':all'; #entity defintion my $entity_manager = Persistence::Entity::Manager->new(name => 'my_manager', connection_name => 'test'); my $emp_entity = Persistence::Entity->new( name => 'emp', alias => 'ep', primary_key => ['empno'], columns => [ sql_column(name => 'empno'), sql_column(name => 'ename', unique => 1), sql_column(name => 'job'), sql_column(name => 'deptno'), ], ); my $dept_entity = Persistence::Entity->new( name => 'dept', alias => 'dt', primary_key => ['deptno'], columns => [ sql_column(name => 'deptno'), sql_column(name => 'dname'), sql_column(name => 'loc') ], ); $dept_entity->add_to_many_relationships(sql_relationship(target_entity => $emp_entity, join_columns => ['deptno'], order_by => 'deptno, empno')); $entity_manager->add_entities($dept_entity, $emp_entity); #object mapping package Employee; use Abstract::Meta::Class ':all'; use Persistence::Entity ':all'; use Persistence::ORM ':all'; entity 'emp'; column empno=> has('$.id'); column ename => has('$.name'); column job => has '$.job'; to_one 'dept' => ( attribute => has ('$.dept', associated_class => 'Department'), cascade => ALL, fetch_method => EAGER, ); package Department; use Abstract::Meta::Class ':all'; use Persistence::Entity ':all'; use Persistence::ORM ':all'; entity 'dept'; column deptno => has('$.id'); column dname => has('$.name'); column loc => has('$.location');
Represents to one relationship. Supports eager, lazy fetch, cascading operation (inert/update/delete).
to_one method by ':all' tag.
Create a new instance of to one relation. Takes associated entity's id as parameters and list of named parameters for Persistence::Relationship::OneToMany constructor.
one_to_many 'wsus_user_service' => ( attribute => has('@.membership' => (associated_class => 'Membership')), fetch_method => EAGER, cascade => ALL, );
Deserialises relation attribute
Inserts relationship data.
Merges relationship data.
Persistence::Relationship Persistence::Entity Persistence::Entity::Manager Persistence::ORM
The Persistence::Relationship::ToOne module is free software. You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.
Adrian Witas, <adrian@webapp.strefa.pl</gt>
To install Persistence::Entity, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Persistence::Entity
CPAN shell
perl -MCPAN -e shell install Persistence::Entity
For more information on module installation, please visit the detailed CPAN module installation guide.