On 7/19/06 6:35 PM, [EMAIL PROTECTED] wrote: > I've found a minor glitch, though: Adding relationships to a table > doesn't seem to work after auto_initialize() gets called. In fact, > a call to add_relationships() *after* auto_initialize() will simply > be ignored. Calling add_relationships() *before* auto_initialize(), > works fine, though.
It's not "ignored." It does just what it's supposed to do: it adds metadata for a new relationship :) What you mean is that no new methods are created for you. Here's what I wrote in a thread from a few weeks ago: "Adding or modifying columns or relationships does not automatically cause any methods to be created. You're merely modifying the metadata. The method creation process reads the metadata, but it is a separate task controlled by its own methods. Methods are created during calls to initialize() or auto_initialize(). There are also explicit make_*_methods() methods. Finally, each column and relationship has its own make_methods() call used to make methods just for that particular piece of metadata." So, if you add or modify a column, foreign key, or relationship, you must also subsequently cause the appropriate make_methods() methods to be called to, well, make the methods :) At that point, if some methods have already been created (say, because you already auto_initialize()d once), then you have to decide what to do if/when there is a conflict with an existing method. Read about the "preserve_existing" and "replace_existing" parameters in the Rose::DB::Object::Metadata documentation for more information. > use base "My::DB::Object"; > __PACKAGE__->meta->table('one'); > > __PACKAGE__->meta->auto_initialize(); > > __PACKAGE__->meta->add_relationships( > myrel => { > type => "one to one", > class => "Two", > column_map => { to_two => 'id' }, > }); As a side note, you should consider using the (relatively new) setup() method instead of calling table(), add_relationships(), etc. separately. The setup() method is the "officially recommended" way to do it, since it will prevent a class from being "double-initialized" accidentally (and it saves some typing too). To auto-initialize in a setup() call, just pass a key/value pair like this: auto_initialize => [], at the end of the setup() params. -John ------------------------------------------------------------------------- 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