Strange, I've been struggling with exact same issue for hours today  . 
I've attached a test case. Fails at run time - no load time errors.
The test case contents are repeated here for reference:

SQL:
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)
);

t/Product.pm:
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->relationships(
           product_details => {
                  type  => 'one to many',
                  class => 't::ProductDetail',
                  column_map => { id => 'product_id' },
           }
);

warn __PACKAGE__->meta->perl_class_definition(indent => 2, braces => 'bsd');

foreach my $rel (t::Product->meta->relationships) {
      warn "RelationShip : " , $rel->name, ': ', $rel->type, "\n";
}

1;
__END__

t/ProductDetail.pm:
package t::ProductDetail;
use strict;
use t::DBConn;
use base 'Rose::DB::Object';

sub init_db { return t::DBConn->new; }
__PACKAGE__->meta->auto_initialize;

#warn __PACKAGE__->meta->perl_class_definition(indent => 2, braces => 'bsd');

1;
__END__

t/DBConn.pm:
package t::DBConn;
use strict;
use warnings;

use base qw(Rose::DB);
__PACKAGE__->use_private_registry;
__PACKAGE__->register_db(
      driver   => 'pg',
      database => 'photos',
      host     => 'localhost',
      username => 'photo',
      password => '',
);

1;
__END__

t/product_test.t : 
#!/usr/bin/perl
use strict;
use warnings;
use t::ProductDetail;
use t::Product;
use Test::More qw(no_plan);
use Test::Exception;

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'; #### this test fails

lives_ok { $o_prod->save } 'saved';

__END__



  - Praveen  

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

On 1/15/07, Cory Bennett <[EMAIL PROTECTED]> wrote:
> I am not sure what I am missing.  I have a Product with relation like:
>     blocks => {
>         type       => 'one to many',
>         class      => 'Block',
>         column_map => { product_id => 'product_id' },
>     },
>
> But when I try the "add_blocks" function it does not seem to exist:
>
> use Product;
> my $p = Product->new(id => 1)->load;
> $p->add_blocks({name => "testing"});
>
> Can't locate object method "add_blocks" via package "Product"
> Rose::DB::Object::AUTOLOAD('Product=HASH(0x1a7039c)', 'HASH(0x224b778)')
> called at ./product.t line 42

Everything there looks right to me.  One possible cause of errors like
this may be a syntax error in a related module (e.g., Block.pm).  Due
to the way that RDBO sometimes has to defer relationship creation,
errors in modules loaded on-demand are not always propagated.  (The
trouble is how to distinguish between a missing module or class, and
one that exists but has errors in it.  String matching on $@ is not
fun...)

If you're sure there are no syntax errors in any modules involved, can
you post a small, self-contained example that reproduces the bug?

-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




Attachment: missing_relationship_bug.tar
Description: Binary data

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