Please take a look at this gist http://gist.github.com/395267 . It seems inverse_of is not working as I expect it to. Or am I missing something here? Thanks -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
> It seems inverse_of is not working as I expect it to. Or am I missing > something here?inverse_of isn''t an identity map, it only handles traversing associations. So in your case: dungeon.traps.map {|t| t.dungeon.object_id } All those object instances will be the same. -- Cheers Koz -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Thanks Michael for the clarification. Any thoughts on should Trap.first.dungeon be blowing up? - Neeraj On May 9, 6:30 pm, Michael Koziarski <mich...@koziarski.com> wrote:> > It seems inverse_of is not working as I expect it to. Or am I missing > > something here? > > inverse_of isn''t an identity map, it only handles traversing > associations. So in your case: > > dungeon.traps.map {|t| t.dungeon.object_id } > > All those object instances will be the same. > > -- > Cheers > > Koz > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-core?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
> Any thoughts on should Trap.first.dungeon be blowing up?Yes, you want inverse_of=>:traps, not :trap. -- Cheers Koz -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Should inverse_of work with scopes? For example, the following loads different dungeons: dungeon.traps.order(''id desc'').map { |t| t.dungeon.object_id } On May 9, 4:25 pm, Michael Koziarski <mich...@koziarski.com> wrote:> > Any thoughts on should Trap.first.dungeon be blowing up? > > Yes, you want inverse_of=>:traps, not :trap. > > -- > Cheers > > Koz > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-core?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
> Should inverse_of work with scopes? For example, the following loads > different dungeons: > > dungeon.traps.order(''id desc'').map { |t| t.dungeon.object_id }The current implementation only does that for the instances on the associations themselves, not for values returned by finders. If you wanted to investigate making that change you could give it a go, but it''s probably a fairly intrusive change and not really suitable for inclusion until 3.1. Of course, who knows, maybe it''d be easy :) -- Cheers Koz -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
It looks feasible to pass along a new :inverse option to NamedScope::scope, and further along as a "@inverse_value" variable to Relation. It would need to carry both the association @owner and the name of the owner attribute. In Relation#to_a, it would finally be used on the loaded records. Another option is to add an :after_load callback, which gets called by Relation#to_a for each loaded record. Seems a bit heavyweight right now, but separates the responsibilities. Thinking out loud won''t get us anywhere. I''ll try tinkering with it in the meantime. On May 28, 6:15 pm, Michael Koziarski <mich...@koziarski.com> wrote:> > Should inverse_of work with scopes? For example, the following loads > > different dungeons: > > > dungeon.traps.order(''id desc'').map { |t| t.dungeon.object_id } > > The current implementation only does that for the instances on the > associations themselves, not for values returned by finders. > > If you wanted to investigate making that change you could give it a > go, but it''s probably a fairly intrusive change and not really > suitable for inclusion until 3.1. Of course, who knows, maybe it''d be > easy :) > > -- > Cheers > > Koz-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.