kentaro/data-mapper — Issue #1: Discussion: Relations
Author: tomi-ru
Created: 2012-03-07 08:03:20+00:00
State: open

To begin with, I hope Data::Mapper "Keep it simple" :)

So, how do we implement relation ship system?

This is just my idea, change Data::Mapper::map_data() to

sub map_data {

# snip ...

my $obj = $data_class->new($data);
$obj->SOMESPECIALMETHOD($self) if $obj->isa('Data::Mapper::Data');
$obj;
}

then if the object want to have a child, do this

package My::Mapper::Data::Book;
use base 'Data::Mapper::Data';

sub SOMESPECIALMETHOD {
my ($self, $mapper) = @_;
$self->{author} = $mapper->find(author => { id => $self->param('author_id') });
}

discussions:

* how do u think about this?
* Is it should support chain action? `$mapper->update($book);` does `$mapper->update($book);` AND `$mapper->update($book->{author});`
* is it better `if $obj->can('SOMESPECIALMETHOD")` instead of `if $obj->isa('Data::Mapper::Data')` for POPO friendly?