On 10/24/06, Graham Barr <[EMAIL PROTECTED]> wrote:
> create table user_connections (
>    id      int unsigned not null auto_increment primary key,
>    from_id int unsigned not null,
>    to_id   int unsigned not null,
>    type    enum('neighbor', 'friend', 'family'),
>    unique  key (from_id, to_id),
>    key     (to_id),
>    constraint foreign key (from_id) REFERENCES users(id),
>    constraint foreign key (to_id) REFERENCES users(id)
> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
>
> The problem is that by default RDBO creates the metadata like
>
>    foreign_keys => [
>      user => {
>        class       => 'MyClass::User',
>        key_columns => {
>          from_id => 'id',
>          to_id   => 'id',
>        },
>      },
>    ],
>
> Which does not look right.

Here's what it looks like after I've removed
foreign_key_name_generator() and fixed the MySQL 5.0.6+ bug:

    foreign_keys => [
      user => {
        class       => 'My::User',
        key_columns => { from_id => 'id' },
      },

      user_obj => {
        class       => 'My::User',
        key_columns => { to_id => 'id' },
      },
    ],

Due to the way the tables are named (users and user_connections) RDBO
also detects and sets up many-to-many relationships in the My::User
class:

    relationships => [
      user_objs => {
        column_map    => { from_id => 'id' },
        foreign_class => 'My::User',
        map_class     => 'My::UserConnection',
        map_from      => 'user',
        map_to        => 'user_obj',
        type          => 'many to many',
      },

      users => {
        column_map    => { to_id => 'id' },
        foreign_class => 'My::User',
        map_class     => 'My::UserConnection',
        map_from      => 'user_obj',
        map_to        => 'user',
        type          => 'many to many',
      },
    ],

The fk an drelationship names are determined by
auto_foreign_key_name() and auto_relationship_name_many_to_many(),
respectively, both of which are in the ConventionManager.  I think
it's a reasonable solution (even if the results are not exactly pretty
in the scenario above) and straightforward to customize in a single
place (the CM), so I'm going to go with this solution unless there are
any objections (and assuming the test suite still passes ;)

-John

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to