Oryx::DBM::Association::Reference - DBM implementation of reference associations


Oryx documentation Contained in the Oryx distribution.

Index


Code Index:

NAME

Top

Oryx::DBM::Association::Reference - DBM implementation of reference associations

SYNOPSIS

Top

See Oryx::Association::Reference.

DESCRIPTION

Top

This class implements the reference association for classes stored within Oryx::DBM connections.

SEE ALSO

Top

Oryx, Oryx::DBM, Oryx::Association::Reference

AUTHOR

Top

Richard Hundt <richard NO SPAM AT protea-systems.com>

COPYRIGHT AND LICENSE

Top


Oryx documentation Contained in the Oryx distribution.

package Oryx::DBM::Association::Reference;

use base qw(Oryx::Association::Reference);

sub create {
    my ($self, $proto, $param) = @_;
}

sub retrieve {
    my ($self, $proto, $id) = @_;
    my $f_key = $self->class->table."_id";
    my $f_id  = $proto->{ $f_key };
    $proto->{ $f_key } = $self->class->dbm->get( $f_id )
      if defined $f_id;
}

sub update {
    my ($self, $proto, $obj) = @_;
    my $accessor = $self->role;
    if (tied($obj->{$accessor})->changed) {
	my $f_key = $self->class->table.'_id';
	if (ref($obj->$accessor)) {
	    $proto->{ $f_key } = $obj->$accessor->id;
	} else {
	    $proto->{ $f_key } = $obj->$accessor;
	}
    }
}

sub delete {
    my $self = shift;
    my ($proto, $obj) = @_;
    if ($self->constraint eq 'Composition') {
	# cascade the delete
	my $accessor = $self->role;
	$obj->$accessor->dbm->delete($obj->id);
    }
    $self->update(@_);
}

sub search {

}

sub construct {
    my ($self, $obj) = @_;
    my $assoc_name = $self->role;
    my @args;
    if ($obj->{$assoc_name} and defined $obj->{$assoc_name}->{id}) {
	@args = ($self, $obj->{$assoc_name}->{id});
    } else {
	@args = ($self, $obj->{$self->class->table.'_id'});
    }
    tie $obj->{$assoc_name}, __PACKAGE__, @args;
}

1;
__END__