Created
February 13, 2009 03:57
-
-
Save pat/63040 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Goal is => Client.first.items... Can do with finder_sql, but want an activerecord way! | |
class Client < ActiveRecord::Base | |
has_many :contacts | |
has_many :tasks, :through => :contacts | |
# has_many :items, :through => :tasks # THIS DOESNT WORK | |
def items | |
@items ||= self.tasks.collect { |task| task.items }.flatten | |
end | |
end | |
class Contact < ActiveRecord::Base | |
belongs_to :client | |
has_many :tasks | |
end | |
class Task < ActiveRecord::Base | |
belongs_to :contact | |
has_many :items | |
end | |
class Item < ActiveRecord::Base | |
belongs_to :task | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment