-
-
Save stevehodges/e85a1e367d546d527984 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
class Post < ActiveRecord::Base | |
has_many :comments | |
belongs_to :approved_version, class_name: name | |
has_one :draft, class_name: name, foreign_key: :approved_version_id | |
amoeba do | |
include_association :comments | |
exclude_association [:approved, :draft] | |
customize(lambda {|live_obj, draft_obj| | |
# This only sets approved_version_id on Post model, doesn't get passed down to its child comments | |
draft_obj.approved_version_id = live_obj.id | |
}) | |
end | |
end | |
class Comment < ActiveRecord::Base | |
belongs_to :post | |
has_many :ratings | |
belongs_to :approved_version, class_name: name | |
has_one :draft, class_name: name, foreign_key: :approved_version_id | |
amoeba do | |
include_association :ratings | |
exclude_association [:approved, :draft] | |
customize(lambda {|live_obj, draft_obj| | |
# This only sets approved_version_id on Comment model, doesn't get passed down to its child ratings | |
draft_obj.approved_version_id = live_obj.id | |
}) | |
end | |
end | |
class Rating < ActiveRecord::Base | |
belongs_to :comment | |
belongs_to :approved_version, class_name: name | |
has_one :draft, class_name: name, foreign_key: :approved_version_id | |
# Ah crap, the approved_version_id isn't getting set | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment