Skip to content

Instantly share code, notes, and snippets.

@texel
Created May 14, 2009 20:52
Show Gist options
  • Save texel/111908 to your computer and use it in GitHub Desktop.
Save texel/111908 to your computer and use it in GitHub Desktop.
class Widget < ActiveRecord::Base
has_many :asset_maps, :as => :owner
has_many :assets, :through => :asset_maps
...
end
class AssetMap < ActiveRecord::Base
belongs_to :owner, :polymorphic => true
belongs_to :asset
end
class Asset < ActiveRecord::Base
def owners
asset_maps.collect { |asset_map| asset_map.owner }
end
def after_create
owners.each { |owner| owner.asset_created }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment