On 4/24/06 5:52 PM, Clayton Scott wrote: > My schema has a table "address". When using the default ConventionManager > and autogenerating classes the coresponding class will have it's last > 's' dropped > to become "Addres". > > I expected that using RDBO::ConventionManager::Null would prevent that > from occuring.
The convention manager is asked to "fill in the blank" when there is no explicit information given for a piece of metadata. When you use the Loader, auto_initialize(), or even if you set up a class manually and just leave certain pieces of information out, the convention manager is called upon to provide the missing information. Here's an example of a convention manager method: table_to_class(). Given a table name, it's supposed to return a name for the RDBO-derived class to front that table. Now consider the Null convention manager. The docs say that it's "a singleton convention manager that does nothing." That last part is the key: it does nothing! That is, it never returns any useful information to fill in those blanks. If you call table_to_class() on the Null convention manager, it returns undef or an empty list (depending on context). Nothing! :) Obviously, using the Null convention manager will not solve your problem. When RDBO calls table_to_class('address') to generate the appropriate class name for that table, it's going to get back undef rather than "addresses" or "address" or anything else useful. So, why would anyone ever want to use the Null convention manager? It's useful for people who want to make sure that they explicitly provide all metadata. Using the Null convention manager ensures that no information is automatically created for you. If you leave something essential out, you'll get an error instead of a "best guess" from the CM. Some people like that assurance. As for your particular problem, you've discovered that the default RDBO CM expects table names to be plural, as documented here: http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object/ConventionMana ger.pm#SUMMARY_OF_DEFAULT_CONVENTIONS You've also discovered that the default CM is not too smart about converting (what it thinks are) plural words to singular. The solution is to create your own convention manager subclass. In your CM subclass, override the table_to_class() method (or just override the plural_to_singular() method) to do the right thing when the word "address" is passed. Then tell your common RDBO base class to use your custom convention manager subclass (or specify it as a parameter to the Loader, if you're using it). (In fact, you don't have to make a subclass at all if you simply specify a custom plural_to_singular_function() for the default convention manager. But the subclass solution is more flexible in the long-run.) Here's a (very primitive) example: package My::ConventionManager; use base 'Rose::DB::Object::ConventionManager'; sub plural_to_singular { my($self, $word) = @_; return 'address' if($word eq 'address'); # already singular! return $self->SUPER::plural_to_singular($word); } ... package My::Base; use base 'Rose::DB::Object'; use My::ConventionManager; __PACKAGE__->meta->convention_manager('My::ConventionManager'); (That's off the top of my head, so please forgive any errors/typos.) -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