----- Original Message ----
From: John Siracusa <[EMAIL PROTECTED]>

>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

Thanks. Are you saying, Loader will detect these foreign key based 
relationships and generate
methods accordingly - something that auto_initialize is not able to do (unless 
we load the modules
in proper order)?
In any case, I tried using loader and it still doesn't create 'product_details' 
relationship in the
Product class:

my %table_meta;
my $all_code;
my $db_loader  = Rose::DB::Object::Loader->new(
                      db                =>  $db_conn,
                      class_prefix   =>  't',
                      with_managers  =>  1,
                      base_classes   => 't::DBModelBase',
                      post_init_hook =>  sub {
                                     my $meta  = shift;
                                     if (my $table = $meta->table) {
                                         my $class = $meta->class;
                                         my $class_code = 
$meta->perl_class_definition(braces => 'bsd');
                                         $table_meta{$table} = $meta;
                                         $all_code .= "$class_code\n";
                                     }
                      },
    );
$db_loader->make_classes;
print $all_code,"\n---------\n";

This prints(among other things):

package t::MoreProductDetail;

use strict;

use base qw(t::DBBase);

__PACKAGE__->meta->setup
(
    table   => 'more_product_details',

    columns =>
    [
        more_product_detail_id => { type => 'serial', not_null => 1 },
        product_id             => { type => 'integer', not_null => 1 },
        product_desc           => { type => 'varchar', length => 100 },
    ],

    primary_key_columns => [ 'more_product_detail_id' ],
);

1;



As you can see, it didn't even detect FK from more_product_details to 
product_details..let alone
the relationship in Product class.
However, I go ahead and try this anyway:
my $new_p = t::Product->new;
$new_p->product_details(product_name => 'h') ;
$new_p->save;
which dies :
DBD::Pg::st execute failed: ERROR:  current transaction is aborted, commands 
ignored until end of transaction block
which seems unrelated to this problem but I'm not sure anymore.

The FK is definitely there in the database:
pg=>\d+ more_product_details
                                                          Table 
"public.more_product_details"
         Column         |          Type          |                              
         Modifiers        | Description
------------------------+------------------------+---------------------------------------------------------------------------------------+-------------
 more_product_detail_id | integer                | not null default 
nextval('more_product_details_more_product_detail_id_seq'::regclass) |
 product_id             | integer                | not null        |
 product_desc           | character varying(100) |        |
Indexes:
    "more_product_details_pkey" PRIMARY KEY, btree (more_product_detail_id)
Foreign-key constraints:
    "more_product_details_product_id_fkey" FOREIGN KEY (product_id) REFERENCES 
products(id)


What's the most reliable way to auto-detect such relations (at least simple FK 
based one-many relations)? Or one must 'hand-decorate' the generated code 
always? 


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