Guest User

Untitled

a guest
May 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. ## db/migrate/product_proxy.rb
  2.  
  3. ProxyMigration < Something
  4. def self.up
  5. create_table :product_proxies do |t|
  6. t.belongs_to :product # product_id
  7. t.belongs_to :manufacturer # if of the Manufacturer object
  8. t.integer :alternate_id # the id the manufacturer gives it.
  9. end
  10. end
  11.  
  12. def self.down
  13. drop_table :product_proxies
  14. end
  15. end
  16.  
  17. ## app/models/product.rb
  18.  
  19. class Product < ActiveRecord::Base
  20. has_one :product_proxy
  21. has_one :manufacturer, :through => :product_proxy
  22. end
  23.  
  24. ## app/models/product_proxy.rb
  25.  
  26. class ProductProxy < ActiveRecord::Base
  27. belongs_to :product
  28. belongs_to :manufacturer
  29.  
  30. named_scope :alternate do |product|
  31. { :conditions => { :product => product } }
  32. end
  33. end
Add Comment
Please, Sign In to add comment