
has n :through relationships should accept Query::Path
Reported by coryodaniel | September 5th, 2008 @ 12:58 PM
Has many relationships let you add a conditional association, which is cool. But working with has many :through and trying to specify a conditional association, I noticed you can't specify the condition on the Through model, only the model that you have many of.
Given: http://pastie.org/266774
It would be nice to be able to do: Person.get(1).peers
And only get the 'active' peers based on the relationship.
I know that you can put the condition on the: has n, :connections, :active => true
But this hides all connections, if Im working with connections Id like to be able to access inactive ones incase Id like to activate them, but when viewing peers one should only see active connections.
Did I make any sense?
Comments and changes to this ticket
-
thefool808 September 5th, 2008 @ 01:20 PM
shouldn't you do something like the following?:
has n, :active_connections, :class_name => 'Connection', :active => true has n, :peers, :through => :active_connections
?
-
-
Aaron Qian September 12th, 2008 @ 01:15 AM
You can pass a property as the conditions like this:
has n, :peers, :through => :connections, :class_name => 'Person', Connection.properties[:active] => true
if you use "Connection.active" => true doesn't work... I don't know why...
Maybe someone can make it work better...
-
Dan Kubb (dkubb) January 8th, 2009 @ 05:09 AM
- State changed from new to accepted
- Assigned user changed from Sam Smoot to Dan Kubb (dkubb)
-
Dan Kubb (dkubb) June 16th, 2009 @ 03:32 AM
- Milestone set to 0.10.0
-
Dan Kubb (dkubb) July 23rd, 2009 @ 11:48 AM
- Milestone changed from 0.10.0 to 0.10.1
-
Dan Kubb (dkubb) October 4th, 2009 @ 09:33 PM
- Milestone changed from 0.10.1 to 0.10.2
[project:id#20609 not-tagged:"0.10.0" not-tagged:"0.10.1" milestone:id#51895 bulk edit command]
-
Dan Kubb (dkubb) October 6th, 2009 @ 11:34 AM
- Milestone cleared.
- State changed from accepted to suggestion
- Assigned user cleared.
At the moment, you should not be able to specify conditions for the :through relationship you are "piggybacking" on top of. If you are currently able to with the approach Aaron mentioned, then it's just a side effect of the implementation, and not something intended by DM.. so keep in mind that future refactorings may break this approach.
There are too many ambiguous cases that would have to be resolved before allowing this.
I will mark this as a "suggestion" and revisit it once outstanding m:m issues are resolved, including self referential m:m, and providing m:m capability to non-RDBMS adapters. Once that is done, then we'll know if we can resolve the ambiguous cases or not.
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 »