-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Building a has_many :through with :conditions #7486
Comments
Workaround: use the following: Since arel nodes don't get mangled by the sanitizer/predicate builder and thus will be recognized by the record builder. |
Closing because it seems invalid. Please see #5057 (comment) If you don't agree please ping me |
Yes, disagree. As @ernie states
He is describing conditions being set on the join model. But in my case it's about conditions which should be set on the associated model, not the join model. |
As this never worked and it is documented behavior we can't consider it as a bug. It is more like a feature request. If you want to make it work please open a pull request or start a discussion in the Rails core mailing list to find someone to work to you. |
Sorry, I must be blind... but where is it documented? The documentation I have quoted in my initial report seems to describe exactly the opposite of what you're saying. |
See the last paragraph. If setting the |
Please have a look at my initial post. I did set the My problem are the conditions on the nested relation. A -> AB (join model, no conditions here) -> B (conditions) Conditions on the |
@the8472 ok. Thank you for the explanation. I'm reopening and marking as bug. Sorry for the make you loose your time. |
Quite interesting. Just came across this and here's what I have (trying to remap the class names to the example above):
In this case, if I do
So it's clearly failing. But, interestingly, if I continue:
it seems like it only fails for a new record. Any thoughts? UPDATE: this only happens when you're trying to save the association together with a new object, by replace
|
Careful with that. If i recall correctly that only reloads attributes, not relations. Use |
Doesn't seem to impact in this case, switching to |
@rafaelfranca Is this really a bug? AFAICT the documentation says that it should work for has_many, but it does not say that it will work for hm:t. Just wanted to know whether this is a bug or a feature request. This is different from #5057 because that's passing in the default attributes through create. |
The documentation says
Appropriate for a has_many with conditions would be a join model with pre-filled values according to the conditions. And there also isn't anything in the documentation saying I can't use those two together. |
This is no longer an issue for master. However my gist is failing for |
I'm closing this since |
Originally reported under activerecord-hackery/squeel#161 but it's happening with vanilla rails 3.2.8 too:
It creates the through-association but does not set the conditions on table
B
. I.e.context
is expected to be "foo", not nil.The
Associations::ClassMethods
documentation states the following:The text was updated successfully, but these errors were encountered: