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

Download:
Persistence-Entity-0.07.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.01   Source  

NAME ^

Persistence::Relationship::OneToMany - One to many relationship.

CLASS HIERARCHY ^

 Persistence::Relationship
    |
    +----Persistence::Relationship::OneToMany

SYNOPSIS ^

    #.... entities definition
    my $membership_entity = Persistence::Entity->new(
        name    => 'wsus_user_service',
        alias   => 'us',
        primary_key => ['user_id', 'service_id'],
        columns => [
            sql_column(name => 'user_id'),
            sql_column(name => 'service_id'),
            sql_column(name => 'agreement_flag')
        ],
    );

    my $user_entity = Persistence::Entity->new(
        name    => 'wsus_user',
        alias   => 'ur',
        primary_key => ['id'],
        columns => [
            sql_column(name => 'id'),
            sql_column(name => 'username', unique => 1),
            sql_column(name => 'password'),
            sql_column(name => 'email'),
        ],
        to_many_relationships => [sql_relationship(target_entity => $membership_entity, join_columns => ['user_id'], order_by => 'service_id, user_id')]
    );
    $entity_manager->add_entities($membership_entity, $user_entity);

    # object mapping
    package User;

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

    entity 'wsus_user';
    column id => has('$.id');
    column username => has('$.name');
    column password => has('$.password');
    column email => has('$.email');

    one_to_many 'wsus_user_service' => (
        attribute    => has('@.membership' => (associated_class => 'Membership')),
        fetch_method => EAGER,
        cascade      => ALL,
    );

DESCRIPTION ^

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

EXPORT ^

one_to_many method by ':all' tag.

METHODS

one_to_many

Create a new instance of one to many 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.

delete

Merges relationship data.

SEE ALSO ^

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

COPYRIGHT AND LICENSE ^

The Persistence::Relationship::OneToMany 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: