This project is archived and is in readonly mode.
add has_element? method to models with has_many/through associations
-
Josh Susser
Attaching new patch - previous one was missing a test case.
-
duncanbeevers
Instead of invoking find_by_id and instantiating a new model, could you instead rely on the optimized include? association method?
-
DHH
I don't think I understand the difference between alex.friends.include?(josh) and alex.has_friend?(josh)? (now that the include? call has been optimized to not load the whole collection).
-
Josh Susser
David, this was an extract of something we wrote before include? got that optimization, so yes, it's equivalent functionality now. If you care about Law of Demeter, this little bit of magic lets you avoid chaining off the association. Maybe it's just fluff now. I guess it's all a question of which API you like better.
-
DHH
- State changed from new to resolved
Ah, okay. Yeah, I could definitely see this make sense before the include? fix. I don't think we need it now, though.
