I have an User
model
class User < ActiveRecord::Base
attr_accessible :email, :name
has_many :client_workouts
end
And a ClientWorkout
model
class ClientWorkout < ActiveRecord::Base
attr_accessible :client_id, :trainer_id, :workout_id
belongs_to :client, :class_name => User, :foreign_key => 'client_id'
belongs_to :trainer, :class_name => User, :foreign_key => 'trainer_id'
end
I first want to know what or if I'm doing something wrong when writing the associations. Ideally I want to be able to call a query where I find the user's clients workouts where the user's id matches with client_id
or trainer_id
. So...
user.client_workouts.trainer???