Re: Mapping column values to objects on create() or select().

[prev] [thread] [next] [Date index for 2005/06/23]

From: Tony Bowden
Subject: Re: Mapping column values to objects on create() or select().
Date: 06:52 on 23 Jun 2005
On Thu, Jun 23, 2005 at 03:06:31AM +0100, rcthomas3000+cdbi@xxxxx.xxx wrote:
> I just want to pass the string in the name column instead and have Show DWIM:
>  my $showing = Show->create( 
>     { film => 'Clash of the Titans', theater => 'Cinemegaloplex III', ... } );

> I can envision writing some kind of before_create trigger or a
> deflate for each column to make sure the name refers to a thing that
> exists in the corresponding table, but which is more right?  

I would use a before_create trigger here which calls find_or_create()
with the values given here.

> I really
> want the same thing to handle my selects, too.  Say, return all the 
> showings of my movie by just searching on the string, not retrieving it first.

You can't do that across a many-to-many. If it were a straight has_many
you could pass arguments to the method created with has_many. But I'm
curious as to why Film->retrieve(...)->showings isn't good enough for
you.

Tony

Re: Mapping column values to objects on create() or select().
Tony Bowden 06:52 on 23 Jun 2005

Generated at 16:36 on 28 Jul 2005 by mariachi v0.52