Problem with model associations (1st rails app)
I am developing a small mass administration rails app for our church. It shall allow the planning of future masses, essentially assigning different tasks to different ministrants (acolyte/server/altar boy?).
One should be able to select serving开发者_如何学运维 ministrants (through checkboxes) and assign a task to each ministrant (through option lists), per mass (it does not need to be the same every mass).
My questions are: 1. How would the migrations look like? I.e. which fields of what type are required? 2. How would the model associations look like? Currently, I am assuming 3 classes (Mass, Ministrant, Task).
I found this question: Correct Model Data Structure? (My 1st Rails App) and it looks similar but I don't really know how to apply the solution on this example...
I'd appreciate your help!
3 models: mass, ministrant and task.
In your console:
rails g model Mass date:datetime
rails g model Ministrant name:string role:string
rails g model Task name:string ministrant_id:integer mass_id:integer
In your ruby files:
class Mass < ActiveRecord::Base
has_many :tasks
has_many :ministrants, :through => :tasks
end
class Ministrant < ActiveRecord::Base
has_many :tasks
has_many :masses, :through => :tasks
end
class Task < ActiveRecord::Base
belongs_to :ministrant
belongs_to :mass
end
精彩评论