Hi all I''m having the following method: def setup_owned_system_rights @owned_system_rights = {} system_groups.each do |system_group| system_group.system_rights.each do |system_right| @owned_system_rights[system_right.model_class.to_sym] = {} unless @owned_system_rights[system_right.model_class.to_sym] @owned_system_rights[system_right.model_class.to_sym][system_right.name.to_sym] = true end end end To reduce the queries to the database I''ve written the following SQL statement which returns the same system_rights that the above iterations do: select * from system_rights inner join system_groups_have_system_rights on system_rights.id system_groups_have_system_rights.system_right_id inner join members_belong_to_system_groups on members_belong_to_system_groups.system_group_id system_groups_have_system_rights.system_group_id where members_belong_to_system_groups.member_id = <<logged in member''s ID>> How can I create now ActiveRecord objects (to be more specific: SystemRight model objects) out of the rows I get? Thanks for help :-) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2007-Nov-04 10:53 UTC
Re: Create ActiveRecord instances from a custom query?
On 4 Nov 2007, at 00:49, Joshua Muheim wrote:> How can I create now ActiveRecord objects (to be more specific: > SystemRight model objects) out of the rows I get? >SystemRight.find_by_sql ''some chunk of sql'' Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---