thanks. moving auto_initialize down worked.
However, a call to meta->relationship is not even needed since RDBO defaults to 
many-to-one relationship based upon foreign keys. But, it seems this default 
works only for one FK? 
Consider this:

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';

last test fails with this message:
# died: Can't locate object method "more_product_details" via package 
"t::Product" at /usr/lib/perl5/site_perl/5.8.6/Rose/DB/Obje\ct.pm line 1464

so, 'product_details' method is created  but not 'more_product_details' ? Maybe 
I missed, but is
it in the tutorial or POD somewhere?

Also, adding explicit relationships via calls to meta->relationship leads to 
other errors.

thanks

  - Praveen  
----- Original Message ----
From: John Siracusa <[EMAIL PROTECTED]>
To: Rose-DB-Object <rose-db-object@lists.sourceforge.net>
Sent: Monday, January 15, 2007 6:48:39 PM
Subject: Re: [RDBO] missing add_ for relationship?

On 1/15/07 6:28 PM, Cory Bennett wrote:
>> __PACKAGE__->meta->auto_initialize;
>> __PACKAGE__->meta->relationships(
>>            product_details => {
>>                   type  => 'one to many',
>>                   class => 't::ProductDetail',
>>                   column_map => { id => 'product_id' },
>>            }
>> );
> 
> In your case you are initializing before setting up your relationships.  If
> you move your auto_initialize after the relationships call, then it should
> work fine.

Yes, exactly.  Relationships, columns, foreign keys, and such are just inert
metadata.  The initialize() method and friends read that metadata and create
the actual methods based on it.

-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




-------------------------------------------------------------------------
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

Reply via email to