2006/4/25, John Siracusa <[EMAIL PROTECTED]>:
[...]
> 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.)

I just encontered the same problem ("categories" vs. "category"). I
used Lingua::EN::Inflect::Number to reasolve it elegantly. Based on
this tip [1] i built my own Metadata class:

package My::DB::Metadata;
use strict;
use warnings;

use base 'Rose::DB::Object::Metadata';

use Lingua::EN::Inflect::Number;

sub init_convention_manager {
   my $this = shift;

   # Let the base class make ths convention manager object
   my $cm = $this->SUPER::init_convention_manager(@_);

   # Set the new singular-to-plural function
   $cm->singular_to_plural_function(\&Lingua::EN::Inflect::Number::to_PL);
   $cm->plural_to_singular_function(\&Lingua::EN::Inflect::Number::to_S);

   # Return the modified convention manager
   return $cm;
}

It works just fine.


[1] 
http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object/ConventionManager.pm#TIPS_AND_TRICKS

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