Hi rose-db-object,
first off, Rose::DB* is fantastic, I love it.
I've found a minor glitch, though: Adding relationships to a table
doesn't seem to work after auto_initialize() gets called. In fact,
a call to add_relationships() *after* auto_initialize() will simply
be ignored. Calling add_relationships() *before* auto_initialize(),
works fine, though.
Here's an example, let's create two tables:
CREATE TABLE one (
id int(11) NOT NULL auto_increment PRIMARY KEY,
file varchar(255),
to_two int(11)
);
CREATE TABLE two (
id int(11) NOT NULL auto_increment PRIMARY KEY,
string varchar(255)
);
Then, some code to set up the Rose mapping:
###########################################
package My::DB;
###########################################
use base qw(Rose::DB);
__PACKAGE__->use_private_registry();
__PACKAGE__->register_db(
driver => 'mysql',
database => 'rosetest',
host => 'localhost',
username => 'root',
password => '',
);
###########################################
package My::DB::Object;
###########################################
use base qw(Rose::DB::Object);
sub init_db { My::DB->new(); }
###########################################
package One;
###########################################
use base "My::DB::Object";
__PACKAGE__->meta->table('one');
__PACKAGE__->meta->auto_initialize();
__PACKAGE__->meta->add_relationships(
myrel => {
type => "one to one",
class => "Two",
column_map => { to_two => 'id' },
});
###########################################
package Two;
###########################################
use base "My::DB::Object";
__PACKAGE__->meta->table('two');
__PACKAGE__->meta->auto_initialize();
Note that add_relationships() comes after auto_initialize() in
package One. Now it you call
package main;
my $one = One->new(file => "fwhoa", to_two => 1);
$one->save();
my $two = Two->new(string => "swhoa");
$two->save();
print $one->myrel->string(), "\n";
you'll get
Can't locate object method "myrel" via package "One"
but if you change the code in One to
__PACKAGE__->meta->add_relationships(
myrel => {
type => "one to one",
class => "Two",
column_map => { to_two => 'id' },
});
__PACKAGE__->meta->auto_initialize();
it works fine. Looks like a bug, doesn't it?
-- Mike
Mike Schilli
[EMAIL PROTECTED]
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Rose-db-object mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rose-db-object