Hi folks, I hope you all had a great Christmas. My mail''s subject says it all.. I''ve been in quite a lot situations where I wanted to join data from another table "transparently", using scopes. By transparently I mean that columns from the joined table are merged into the result set as if they were attributes of the actual model. SQL makes this possible with the SELECT statement, where you can do "SELECT donors.*, model_translations.content AS name INNER JOIN model_translations ON ...." so that a donor''s name is actually fetched from another table but still available for sorting etc. Now to implement such a behavior we first need to add the JOIN statement to the finder''s SQL which is easy using dynamic scopes. The SELECT, however can''t easily be added because it would override Rails'' default "donors.*".. I''m willing to hack a patch if there is no particular reason for this implementation but I wanted to check beforehand. Cheers Pascal --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Pascal Ehlert
2008-Dec-31 10:21 UTC
Re: Why aren''t select statements merged among scopes?
Hi Matt, I can use :select, but it overrides any previous :selects defined in other scopes or even the default scope instead of merging with them to select all the fields. I think we have with_exclusive_scope for this behavior and the default should be different. Cheers --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Pascal Ehlert
2009-Jan-02 02:59 UTC
Re: Why aren''t select statements merged among scopes?
I found a ticket on Lighthouse which addresses the same issue, hope someone has an idea how to solve this: http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1295-making-with_scope-merge-selects Pascal On Dec 31, 2008, at 11:21 AM, Pascal Ehlert wrote:> > Hi Matt, > > I can use :select, but it overrides any previous :selects defined in > other scopes or even the default scope instead of merging with them to > select all the fields. > > I think we have with_exclusive_scope for this behavior and the default > should be different. > > Cheers > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---