On 1/15/07, Praveen Ray <[EMAIL PROTECTED]> wrote: > create table products ( > id SERIAL PRIMARY KEY, > product_rating VARCHAR(100) > ); > > create table product_details ( > product_detail_id SERIAL PRIMARY KEY, > product_id INTEGER NOT NULL REFERENCES products (id), > product_name VARCHAR(100) > ); > > create table more_product_details ( > more_product_detail_id SERIAL PRIMARY KEY, > product_id INTEGER NOT NULL REFERENCES products(id), > product_desc VARCHAR(100) > ); > > Product.pm looks like: > package t::Product; > use strict; > use t::DBConn; > use base 'Rose::DB::Object'; > sub init_db { return t::DBConn->new; } > __PACKAGE__->meta->auto_initialize; > __PACKAGE__->meta->make_manager_class; > > 1; > __END__ > > ProductDetail.pm and MoreProductDetail.pm are similar. > > If I try this ,in a test script: > > my $o_prod = t::Product->new; > ok($o_prod, 'empty Product created'); > lives_ok { $o_prod->product_rating('excellent') } 'rating > set'; > lives_ok { > $o_prod->product_details( > { product_name => 'vegetable' } > ) > } 'details survive'; > lives_ok { > $o_prod->more_product_details( > { product_desc => > 'nice product'} > ) > } 'added more details';
You need to load t::ProductDetail and t::MoreProductDetail at some point. Even though auto_load_related_classes() is on by default, there's no way for the call to auto_initialize() inside t::Product to have any idea that the product_details and more_product_details tables (and associated RDBO-derived classes) exist at all unless something, somewhere first loads the t::ProductDetail and t::MoreProductDetail modules. (It looks like the t::ProductDetail class is in memory when your test script is run, because it appears that the "product_details" relationship exists in t::Product.) I suspect that if you put "use t::MoreProductDetail;" and "use t::ProductDetail" in Product.pm, the call to auto_initialize() will create the relationships you expect. To avoid having to manually use() related modules, consider using the Loader to create your modules for you, rather than manually creating each one and auto_initialize()ing. http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object/Loader.pm The make_modules() method in particular will save you a lot of work. -John ------------------------------------------------------------------------- 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 Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object