On Wed, Mar 10, 2010 at 11:16 AM, Jeremy Evans <[email protected]>wrote:

> On Mar 9, 11:36 pm, John Firebaugh <[email protected]> wrote:
> > The fact that one_to_one associations are a thin layer on one_to_many,
> > specifically the need for them to be named in the plural, is causing a
> fair
> > bit of accidental complexity in a custom plugin we have that does heavy
> > reflection on associations.
> >
> > What would be necessary to be able to name one_to_one associations in the
> > singular?
>
> I'm not sure of all the changes that would be needed to make it work.
> It's possible that the changes are extensive enough to require the
> creation of a real one_to_one association.


It was easy to get the specs to pass, but I'm not sure if I'm missing
something. See the attached patch.


> That being said, it would be helpful for you to explain what the
> actual issues you are running into are.  It's possible that we just
> need to add something to the association reflection classes to
> eliminate or at least reduce the complexity.
>

We have a filter interface similar to iTunes smart playlists:

http://www.apple.com/itunes/how-to/index.html#playlists-smartplaylists

The filter criteria support many_to_one and one_to_one relationships using
eager graphing. When serialized, criteria look something like this:

[['book.title', :=, "Where the Wild Things Are"],
 ['book.author.first_name', :=, "Maurice"],
 ['book.first_page.text', :contains, "Max"]]

Assume book -> pages is one-to-many, and book -> first page is one-to-one
based on the constraint page.number = 1. The complexity arises because the
accessor method is #first_page but the association name is :first_pages --
when processing the criteria, we have to special case 'book.first_page.text'
to handle that. If we used 'book.first_pages.text' instead, we would still
need special cases, just in different places. We really need the accessor
name and association name to be the same.

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Attachment: 0001-Support-singular-association-names-when-using-one_to.patch
Description: Binary data

Reply via email to