Skip to content

Instantly share code, notes, and snippets.

@andrewpthorp
Created August 24, 2011 19:16
Show Gist options
  • Save andrewpthorp/1168918 to your computer and use it in GitHub Desktop.
Save andrewpthorp/1168918 to your computer and use it in GitHub Desktop.
class BrandIdentity < ActiveRecord::Base
has_one :library_asset, :dependent => :destroy, :as => :asset
end
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?
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