
Problem with named relationships.
Reported by Austin Bales | November 9th, 2009 @ 05:19 AM
I've been experiencing many problems while trying to create a system of Mailers that are owned by a Person and have many People.
After trying several different approaches and not being entirely certain about the validaty of any of them, http://gist.github.com/229865 seems to describe the issue the best.
People have many Mailers (senders)
Mailers belongs to a Person (potentially people if that worked)
Mailers have many People (recipients)
Comments and changes to this ticket
-
Dan Kubb (dkubb) November 9th, 2009 @ 02:03 PM
- State changed from new to resolved
When you're doing m:m with a custom name you need to specify the intermediary model and relationships explicitly, eg:
If you follow the DM defaults, and just use "has n, :mailers, :through => Resource" inside Person, the explicit intermediary model can be removed, and the relationship in Mailer can become "has n, :people, :through => Resource" too.
-
Dan Kubb (dkubb) November 9th, 2009 @ 02:03 PM
- Assigned user set to Dan Kubb (dkubb)
-
Austin Bales November 9th, 2009 @ 02:39 PM
Thanks Dan,
So, using what you said above, I can created custom relationship and a default relationship at the same time: as seen http://gist.github.com/230255.
Thanks to you and dbussink for all the help!
-
Austin Bales November 9th, 2009 @ 05:40 PM
Okay, so the stranger part of the problem re-appeared.
If I create two people:
Person.create(:name => "Austin")
Person.create(:name => "John")
Person.create(:name => "John")Mailer.create(:person => Person.first, :people => Person.all(:name => John))
Mailer.create(:person => Person.first, :people => Person.all(:name => John))Mailer.first().person # Austin
Mailer.get(2).person # John, What!??!Is this because of the overlap of person and people? How can I fix it?
-
Austin Bales November 9th, 2009 @ 05:42 PM
The above problem is reflected at: http://gist.github.com/230255
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »