Is there a way for Rose to auto-initialize a schema that has a many-to-many
relationship defined?
Here's the schema:
mysqladmin -u root create testdb
CREATE TABLE IF NOT EXISTS firsts (
id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
name VARCHAR(50)
);
CREATE TABLE IF NOT EXISTS seconds (
id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
path varchar(255)
);
CREATE TABLE IF NOT EXISTS first_second_map (
first_id INT NOT NULL REFERENCES firsts (id),
second_id INT NOT NULL REFERENCES seconds (id),
PRIMARY KEY (first_id, second_id)
);
but the code
use strict;
use Rose::DB;
use Rose::DB::Object;
package DB;
use base 'Rose::DB';
__PACKAGE__->use_private_registry;
__PACKAGE__->register_db(
driver => 'mysql',
host => 'localhost',
database=> 'testdb',
username=> 'root',
password=> '',
);
package Object;
use base qw( Rose::DB::Object );
sub init_db { DB->new }
package First;
use base 'Object';
__PACKAGE__->meta->auto_initialize;
package Second;
use base 'Object';
__PACKAGE__->meta->auto_initialize;
package FirstSecondMap;
use base 'Object';
__PACKAGE__->meta->auto_initialize;
package main;
my $f = First->new( id => 1, name => "testing" );
$f->load( speculative => 1);
$f->seconds();
1;
throws an error
DBD::mysql::db column_info failed: Table 'testdb.first_second_maps'
doesn't exist at Rose/DB/Object/Metadata/Auto.pm line 85. Could not
auto-generate columns for class FirstSecondMap
indicating that it doesn't see that 'first_second_map' is a mapping table.
The tutorial says
use ProductColorMap;
...
__PACKAGE__->meta->setup
(
relationships =>
[
colors => { type => 'many to many' },
...
],
...
);
would work, suggesting that the mapping table class has to define
the relationship, but I couldn't get this to work either.
What's the easiest way to set up a many-to-many relationsship with
a mapping table, making maximum use of the convention manager?
-- Mike
Mike Schilli
[EMAIL PROTECTED]
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Rose-db-object mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rose-db-object