# Associations
#
# User: has_many :sources, :as => :sourceable, :dependent => :destroy
#
# Source:
# has_many :source_items
# belongs_to :source_type
# belongs_to :sourceable, :polymorphic => true
#
# SourceItem: belongs_to :source
# source.rb
def self.find_source_for obj
obj.sources.all(:include => [:source_items => {:source => :source_type}]).collect { |s| s.source_items }.flatten! # Can I limit here also the retrieval of source item?
end
Refactorings
No refactoring yet !
ggomeze.myopenid.com
March 20, 2010, March 20, 2010 16:02, permalink
Not sure this is what you mean, but i see some redundant code in your approach
obj.sources.map(&:source_items).flatten!
cna training
April 5, 2010, April 05, 2010 23:50, permalink
Wow this is a great resource.. I’m enjoying it.. good article
For a object (e.g. user), I want to retrieve the related source items. The object is assigned to sources and their respective source items.