On 10/24/05, Sean Davis <[EMAIL PROTECTED]> wrote:
> I am a new user (as of about 2 hours ago).  I have two tables that have a
> one-to-one relationship with a third (so, of course, there is a one-to-many
> from the third to the other two).  The code looks like below.  However, I
> get the following error message on compile and I do have foreign keys
> present in the g_alias and g_refseq tables.  I can't figure out what I am
> doing incorrectly.  Any help?

First question: what version of RDBO are you using?  Second question:
can you post the db schema including all key definitions?

For the error message, it looks like it couldn't auto-generate a name
for the foreign key, which strikes me as a bug.  But I'll need the db
schema to figure it out for sure.

In the meantime, regarding this:

> package AnnoDB::Model::Gene::Alias;
> use base qw(AnnoDB::Model);
>
> __PACKAGE__->meta->table('g_alias');
> __PACKAGE__->meta->relationship
>   (
>    gene => {
>         type => 'one to one',
>         class => 'AnnoDB::Model::Gene::Main',
>         column_map => {gene_id => 'gene_id'},
>        },
>   );
>
> __PACKAGE__->meta->auto_initialize();

The "__PACKAGE__->meta->relationship" line should be
"__PACKAGE__->meta->relationships" with an "s"! :)

But ignoring that for now, if your table has a foreign key, you should
say so in the metadata.  IOW, do this:

__PACKAGE__->meta->foreign_keys
(
   gene => {
     type => 'one to one',
     class => 'AnnoDB::Model::Gene::Main',
     column_map => {gene_id => 'gene_id'},
   },
);

That will actually create a corresponding "one to one" relationship
behind the scenes (this behavior is documented, I believe), but more
importantly, it's an accurate reflection of the underlying table.  The
rule of thumb (which I keep meaning to document) is:

    If the table has a foreign key, then define it with foreign_keys()

Otherwise, feel free to use a "one to one" or "many to one" relationship.

-John


-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Rose-db-object mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to