Closed ppodolsky closed 10 years ago
Where are you seeing registered_subjects
? I was pretty liberal in changing the requirements in the model ticket I finished previously. That column doesn't exist in my code.
For this and other join tables, when the join table can have meaning, I highly suggest naming the join table and using has_many ... through:
or has_one ... through:
.
For example, instead of subjects_experiments
, we would setup models like:
#app/models/experiment.rb
class Experiment < ActiveRecord::Base
has_many :subjects, through: :participation
...
end
#app/models/subject.rb
class Subject < ActiveRecord::Base
belongs_to :experiment, inverse_of: :subjects
...
end
Yeah, my bad. I mispointed another table in the first message, I've corrected it now. And all the talking was about Session, not Experiment, sorry
And about naming, I'm agree with you. But, in this case, I think users_sessions and users_experiments will be more appropriate. Why? Cause table named «participation» or «registration» won't tell us what we are dealing with – experiment or session – and it can be confusable
I think we'll calculate the number of registred subjects to the session S by counting number of rows in joint table SubjectsSessions (UsersSessions) where session_id = S.id . Column registred_subjects in the table Sessions duplicates functionality