Adrian Witas > Persistence-Entity-0.07 > Persistence::Relationship::ManyToMany

Download:
Persistence-Entity-0.07.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.01   Source  

NAME ^

Persistence::Relationship::ManyToMany - Many to many relationship

CLASS HIERARCHY ^

 Persistence::Relationship
    |
    +----Persistence::Relationship::ManyToMany

SYNOPSIS ^

    use Persistence::Relationship::ManyToMany ':all';

#.... entities definition

    my $entity_manager = Persistence::Entity::Manager->new(name => 'my_manager', connection_name => 'test');

    my $emp_project_entity = Persistence::Entity->new(
        name    => 'emp_project',
        alias   => 'ep',
        primary_key => ['projno', 'empno'],
        columns => [
            sql_column(name => 'projno'),
            sql_column(name => 'empno'),
            sql_column(name => 'leader'),
        ],
    );

    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'),
        ],
        value_generators => {empno => 'emp_gen'}, 
        to_many_relationships => [
            sql_relationship(target_entity => $emp_project_entity,
            join_columns => ['empno'], order_by => 'empno, projno')
        ]
    );

    my $project_entity = Persistence::Entity->new(
        name    => 'project',
        alias   => 'pr',
        primary_key => ['projno'],
        columns => [
            sql_column(name => 'projno'),
            sql_column(name => 'name', unique => 1),
        ],
        value_generators => {projno => 'project_gen'},
        to_many_relationships => [
            sql_relationship(target_entity => $emp_project_entity,
            join_columns => ['projno'], order_by => 'projno, empno')
        ]
    );

    $entity_manager->add_entities($emp_project_entity, $emp_entity, $project_entity);

    # object mapping

    package Project;

    use Abstract::Meta::Class ':all';
    use Persistence::Entity ':all';
    use Persistence::ORM ':all';

    entity 'project';
    column projno => has('$.id');
    column name => has('$.name');

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

    many_to_many 'project' => (
        attribute        => has('%.projects' => (associated_class => 'Project'), index_by => 'name'),
        join_entity_name => 'emp_project',
        fetch_method     => LAZY,
        cascade          => ALL,
    );

DESCRIPTION ^

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

EXPORT ^

many_to_many by ':all' tag.

ATTRIBUTES

join_entity_name

Join entity name.

METHODS

many_to_many
deserialise_attribute

Deserialises relation attribute

insert

Inserts relationship data.

merge

Merges relationship data.

delete

Deletes many to many association.

_associate_relationship_data

SEE ALSO ^

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

COPYRIGHT AND LICENSE ^

The Persistence::ManyToManyRelationship 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

syntax highlighting: