我有这个型号:
class Student < ActiveRecord::Base
has_many :tickets
has_many :movies, through: :tickets
end
class Movie < ActiveRecord::Base
has_many :tickets, dependent: :destroy
has_many :students, through: :tickets
belongs_to :cinema
end
class Ticket < ActiveRecord::Base
belongs_to :movie, counter_cache: true
belongs_to :student
end
class Cinema < ActiveRecord::Base
has_many :movies, dependent: :destroy
has_many :students, through: :movies
has_many :schools, dependent: :destroy
has_many :companies, through: :yard_companies
end
class School < ActiveRecord::Base
belongs_to :company
belongs_to :student
belongs_to :cinema, counter_cache: true
end
class Teacher < ActiveRecord::Base
belongs_to :movie, counter_cache: true …Run Code Online (Sandbox Code Playgroud)