Advertisement
Guest User

Untitled

a guest
Sep 19th, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. class User < ActiveRecord::Base
  2.  
  3. has_many :device_ownerships
  4. has_many :devices, :through => :device_ownerships
  5.  
  6. class Device < ActiveRecord::Base
  7. has_one :device_ownership
  8. has_one :user, :through => :device_ownership
  9. end
  10.  
  11.  
  12. class DeviceOwnership < ActiveRecord::Base
  13. belongs_to :user
  14. belongs_to :device
  15. end
  16.  
  17. def create
  18. user = User.create
  19. device = Device.create
  20. device_ownership = DeviceOwnership.create(:serial_numer => params[:device_serial_number], :device_id => device.id, :user_id => user.id)
  21. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement