has_many conditions or proc on foreign key
- by ere
I have a has_many association between two models using a date as both the foreign and primary key for each model.
It works perfectly one way but not the other.
Works
has_one :quiz_log, :primary_key => :start_at, :foreign_key => :start_at
Doesn't work
has_many :event_logs, :primary_key => :start_at, :foreign_key => :start_at
The reason being (i think) because the start_at on QuizLog is a date and the start_at on EventLog is a datetime. So it returns nil trying to match the exact datetime on a simple date.
How can I cast the foreign_key start_at on the second statement to convert it first from datetime to simply date so it will match the second model?