
Has many through adds extra property to "middle" model
Reported by Tony Pitale | July 27th, 2009 @ 08:23 AM | in 0.10.0
Comments and changes to this ticket
-
Tony Pitale July 27th, 2009 @ 08:24 AM
- Tag set to edge, join, properties, regression, relationships
If you comment line 41, the extra property is not added.
-
-
Martin Gamsjaeger (snusnu) July 27th, 2009 @ 08:49 AM
- State changed from new to unconfirmed
- Assigned user set to Dan Kubb (dkubb)
- Milestone set to 0.10.0
I can confirm that this happens. I must say that I find it kind of weird anyway that relationship declarations establish the foreign key properties. That may just be me, but I like it more explicit (although that might be considered as redundant by most)
-
Martin Gamsjaeger (snusnu) July 27th, 2009 @ 08:50 AM
- State changed from unconfirmed to confirmed
bah, wanted to confirm it ...
-
Tony Pitale July 27th, 2009 @ 08:54 AM
namelessjon identified this as the possible point of change: http://github.com/datamapper/dm-core/commit/400b327548d2e23a39248d0...
-
Jonathan Stott (namelessjon) July 27th, 2009 @ 03:57 PM
Just to say, that was the commit I found via using git bisect, and a modified version of Tony's script. So I'm fairly confident that's the commit responsible.
-
Tony Pitale August 4th, 2009 @ 11:59 AM
The problem seems to be more of a conceptual one. DM assumes that if I have a has-n with :through, it will be a many to many, and that the table we're going through is going to belong to both tables being joined. This isn't always the case, as I have the potential to go only one way. It's a one-to-many, through another one-to-many. The solution to this is only adding the key for the direction being declared.
Given the desired situation:
thing1 > joiner > thing2 thing1 has n joiners thing1 has n thing2s, :through joinersJoiner would only belong_to thing1, and so would only have the FK thing1_id
DM is assuming the situation to be
thing1 > joiner < thing2and the problem is this assumption occurs as soon as the :through key is used.
Can OneToMany::Relationship be used in all cases?
-
-
Tony Pitale August 4th, 2009 @ 02:07 PM
- Title changed from Has many through adds extra property to "middle" model to [resolved] Has many through adds extra property to "middle" model
-
Tony Pitale August 4th, 2009 @ 02:09 PM
In order to achieve has n through a class that does not belong to both the classes it is joining, I had to use the newly added via option. This is important/awesome and should be added to the docs asap.
-
Martin Gamsjaeger (snusnu) August 4th, 2009 @ 10:00 PM
- Title changed from [resolved] Has many through adds extra property to "middle" model to Has many through adds extra property to "middle" model
Dan mentioned on IRC that he considers any unnecessary property inference to be a bug. Therefore I changed back the title and linked another http://gist.github.com/162407 to demonstrate the problem.
-
Dan Kubb (dkubb) August 18th, 2009 @ 02:59 AM
In this specific case, where the via relationship is setup I should check for relationships in the through_model in the following order:
- The explicit :via option
- The explicit name of the relationship
- The singular name of the relationship
If all three of those do not return any relationship, then I will continue to create the belongs_to association using the singular name.
- The explicit :via option
-
Dan Kubb (dkubb) August 18th, 2009 @ 03:34 AM
- State changed from confirmed to resolved
(from [724bad4d7482a12a2f81c56b7fe211f2aadeb4a2]) Use the relationship name for :via if none provided explicitly
- If neither :via is provided, and the relationship name matches a relationship on the "through model", then use the singular relationship name to either lookup the relationship or create a new belongs_to joining the "through model" and "target model".
- Added missing specs for m:m with :through => 1:m relationship
[#990 state:resolved] http://github.com/datamapper/dm-core/commit/724bad4d7482a12a2f81c56...
-
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 »
People watching this ticket
Referenced by
-
990 Has many through adds extra property to "middle" model [#990 state:resolved] http://github.com/datamapper/dm-co...