This project is archived and is in readonly mode.
[PATCH] Add methods on active record to denote whether any associated objects exist for that association
-
CancelProfileIsBroken
- Tag set to bugmash
-
pjammer
+1 patch verified and all tests pass.
It appears that this method would be very handy, when needed.
-
Nick Quaranto
-1, I don't like the
alias_methodtohas_#{name}and it seems that keeping a similar api to the dirty methods would be better. For example, if a Post has many Comments:post = Post.new post.comments?instead of
post = Post.new post.has_comments?would be a lot cleaner.
-
Josh Nichols
+1 on the feature, -1 on the implementation.
I agree with Nick on excluding has for the methods, ie comments? instead of has_comments?. This would be more in line with what you get from normal attributes.
-
Josh Susser
I think post.comments.any? is a more consistent API. IMO it's better to keep the number of generated methods on the base class to a minimum, and layer this kind of behavior onto the association proxy object.
-
Dan Pickett
-1 on the implementation
I agree with Nick on this as well.
note that #49 was similar and denied - although this has more to do with verifying that the collection is empty or object exists
-
Jeremy Kemper
- State changed from new to wontfix
Enumerable's already got the goods here, so let's not introduce a new overlapping API that only works with AR assocations.
-
Elad Meidar
Here's a patch for 2-3-stable removing the has_#{name} methods and keeps only the #{name}? methods.
-
Elad Meidar
forgot to mention that the patch is applied on master too.
-
Rizwan Reza
verified.
+1 Patch works perfectly in master.
-
CancelProfileIsBroken
- Tag cleared.
- Milestone cleared.
-
avijayr (at gmail)
I would like to point out two things:
1) The usage scenario described was for serialization to xml so that a corresponding ActiveResource could then be queried in a simple(shallow?) way before making a nested call. That is the reason why the implementation has the 'has_'. In the context of a ARecord, the method with '?' makes sense (to be compatible with Rails' notion of asking a question), but when you want to serialize the same, in my case in the to_xml method on ARecord, the '?' has to be treated specially - which is why I provided an alias without the '?'.As far as the presence of the 'has_' - this is present to differentiate between the query to retrieve the associated objects vs the presence of these associated objects.
I hope I made myself clear as to why the implementation was the way it was.
