Created
August 24, 2011 19:16
-
-
Save andrewpthorp/1168918 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 BrandIdentity < ActiveRecord::Base | |
has_one :library_asset, :dependent => :destroy, :as => :asset | |
end |
This file contains hidden or 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
brand_identity = BrandIdentity.new | |
brand_identity.build_library_asset | |
brand_identity.save! | |
# Validation error, asset must be present | |
brand_identity.library_asset | |
# => [Library Asset] | |
brand_identity.library_asset.asset | |
# => nil | |
# Why doesn't it set both sides of the relationship? |
This file contains hidden or 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 LibraryAsset < ActiveRecord::Base | |
belongs_to :asset, :polymorphic => true | |
validates_presence_of :asset | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment