Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## db/migrate/product_proxy.rb
- ProxyMigration < Something
- def self.up
- create_table :product_proxies do |t|
- t.belongs_to :product # product_id
- t.belongs_to :manufacturer # if of the Manufacturer object
- t.integer :alternate_id # the id the manufacturer gives it.
- end
- end
- def self.down
- drop_table :product_proxies
- end
- end
- ## app/models/product.rb
- class Product < ActiveRecord::Base
- has_one :product_proxy
- has_one :manufacturer, :through => :product_proxy
- end
- ## app/models/product_proxy.rb
- class ProductProxy < ActiveRecord::Base
- belongs_to :product
- belongs_to :manufacturer
- named_scope :alternate do |product|
- { :conditions => { :product => product } }
- end
- end
Add Comment
Please, Sign In to add comment