Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: Re: Re: Class::DBI has_many

by arc_of_descent (Hermit)
on Dec 29, 2003 at 14:07 UTC ( [id://317432]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Class::DBI has_many
in thread Class::DBI has_many


Fine. I understand.
Anyways.. this is what I tried

Page.pm
__PACKAGE__->has_many(columns => [ 'Page_column' => 'column_id' ]);


Page_column.pm
__PACKAGE__->has_many(columns => 'Column');


Column.pm
__PACKAGE->has_a(column_id => 'Column');

I know there is no free service available here, but I very much appreciate any help available. :-)
--
arc_of_descent

Replies are listed 'Best First'.
5Re: Class::DBI has_many
by jeffa (Bishop) on Dec 29, 2003 at 14:20 UTC
    You are close. Try this instead:
    package Page; __PACKAGE__->has_many(columns => 'Column'); package Page_column; __PACKAGE__->has_a(page_id => 'Page'); __PACKAGE__->has_a(column_id => 'Column'); package Column; __PACKAGE__->has_many(pages => 'Page');
    And if your immediate question is "Why can columns have multiple pages", then you need to go back to your 1NF 1:N design, like kal suggested. Your second example is what i call a cross table, and the tables on the ends are the "many" relationships.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    

      Hi,

      Thanks for suggestion, but unfortunately I tried but it does not seem to work for me :-( I am posting my code, so that people can get a closer look. :-)

      Page.pm

      package DBI::Page; use base 'DBI::Sec_scheduler'; __PACKAGE__->table('page'); __PACKAGE__->columns(All => ( "page_id", "page_title", ) ); __PACKAGE__->has_many(cols => 'DBI::Column'); 1;
      Page_column.pm
      package DBI::Page_column; use base 'DBI::Sec_scheduler'; __PACKAGE__->table('page_column'); __PACKAGE__->columns(All => ( "page_id", "column_id", ) ); __PACKAGE__->has_a(page_id => 'DBI::Page'); __PACKAGE__->has_a(column_id => 'DBI::Column'); 1;
      Column.pm
      package DBI::Column; use base 'DBI::Sec_scheduler'; __PACKAGE__->table('column'); __PACKAGE__->columns(All => ( "column_id", "column_title", ) ); __PACKAGE__->has_many(pages => 'DBI::Page'); 1;
      test.pl
      #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use lib '/home/rohan/work/sec_scheduler/modules'; use sec_scheduler; my $p = DBI::Page->retrieve(page_id => 1); print Dumper($p->cols);

      After I run test.pl, I get the foll. error:

      Use of 'croak' is deprecated at /usr/lib/perl5/site_perl/5.8.0/Class/DBI.pm line 950. Use '_croak' instead is not a column of DBI::Column at ./test.pl line 9
      --
      arc_of_descent

        That's a bug (reported) in Class::DBI. Edit that line to use ->_croak instead;

        MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
        I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
        ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Re: Re: Re: Re: Class::DBI has_many
by PodMaster (Abbot) on Dec 29, 2003 at 14:32 UTC
    I believe that should be  __PACKAGE__->has_many(columns => [ 'Page_column' => 'columns' ]); in Page.pm.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://317432]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-25 11:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found