Adrian Witas > Persistence-Entity > Persistence::Relationship::ToOne

Download:
Persistence-Entity-0.07.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.01   Source  

NAME ^

Persistence::Relationship::ToOne - To one relationship

CLASS HIERARCHY ^

 Persistence::Relationship
    |
    +----Persistence::Relationship::ToOne

SYNOPSIS ^

    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');

DESCRIPTION ^

Represents to one relationship. Supports eager, lazy fetch, cascading operation (inert/update/delete).

EXPORT ^

to_one method by ':all' tag.

METHODS

to_one

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,
    );
deserialise_attribute

Deserialises relation attribute

insert

Inserts relationship data.

merge

Merges relationship data. #what if lazy

delete

Merges relationship data.

SEE ALSO ^

Persistence::Relationship Persistence::Entity Persistence::Entity::Manager Persistence::ORM

COPYRIGHT AND LICENSE ^

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.

AUTHOR ^

Adrian Witas, <adrian@webapp.strefa.pl</gt>

syntax highlighting: