On 12/27/05 8:27 AM, John Siracusa wrote:
> On 12/27/05 8:22 AM, John Siracusa wrote:
>> [a bunch of stuff that's not applicable to your situation]

Actually, I was mostly right earlier.  (No, really this time! :)  You have a
conflict in your FooParent class between the foreign key and column names.
As I wrote before:

Foreign keys and relationships have several methods created for them, one of
which (by default) is named exactly like the relationship or foreign key
name.  Columns also (by default) have a method named exactly like the column
name.  So if you have a column named "foo" *and* a relationship or foreign
key named "foo", one of those things won't be able to make its method(s).
This is what's happening to you.

So, here's your FooParent class:

    package FooParent;
    ...
    __PACKAGE__->meta->columns('child', 'parent');
    __PACKAGE__->meta->foreign_keys(
        child  => { class => 'Foo', key_columns => { child  => 'id' } },
        parent => { class => 'Foo', key_columns => { parent => 'id' } },
    );
    ...

Note that you have a column named "child" *and* a foreign key named "child."
When you call initialize(), RDBO will make a "get_set" method for the
"child" column that's named child().  Then, later in the init process, it'll
try to create a "get_set_on_save" method that's *also* named child() for the
foreign key named "child."  When then happens, you get an error like this:

    Cannot create method FooParent::child - method already exists

Earlier, I suggested renaming your db columns, but that's actually a pretty
extreme solution.  Minimally, you can just decide which "thing" is going to
get to use the child() method: the column or the foreign key?

Since foreign key names are arbitrary anyway, it probably makes the most
sense to let the "child" column keep the child() method name, and simply
rename the foreign key.  Ditto for "parent"/parent().  So, the revised
FooParent class would be something like this:

    package FooParent;
    ...
    __PACKAGE__->meta->columns('child', 'parent');
    __PACKAGE__->meta->foreign_keys(
        child_obj  => { class => 'Foo', key_columns => { child  => 'id' } },
        parent_obj => { class => 'Foo', key_columns => { parent => 'id' } },
    );
    ...

with "_obj" added to the foreign key names to keep their "get_set_on_save"
methods from conflicting with the columns' "get_set" methods with the same
names.

Other possible approaches include aliasing the columns or explicitly
specifying the foreign key "get_set_on_save" method names.  But I think
renaming the foreign keys is your best bet.

-John




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to