Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.60 KB | None | 0 0
  1. create_table :channels_displays, :id => false do |t|
  2.   t.integer :display_id
  3.   t.integer :channel_id
  4.   t.integer :position
  5. end
  6.  
  7.  
  8. class Channel < OrganisationData
  9.   has_many :displays, :through => :channel_display
  10. end
  11.  
  12. # this join table has attribute "position"
  13. class ChannelsDisplay < ActiveRecord::Base
  14.   belongs_to :channel
  15.   belongs_to :display
  16. end
  17.  
  18. class Display < OrganisationData
  19.   has_many :channels_display
  20.   has_many :channels, :through => :channels_display, :order => :position
  21. end
  22.  
  23. # but how set the position?
  24. # display = Display.first
  25. # display.channels << Channel.first
  26. # ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement