[TL;DR] Even though the selected events conceptually belong to a record,
the latter has the foreign keys to former. So technically,
is to be changed to
This is the first time I've ran into something like this and it was interesting to realize what it actually means when developing a business logic in Rails.
In this app I'm building, I have Students that have a Record
per year. Each record has several Events. These records also have two
specific events: a test and an audition, registered in the
id's in the record's table.
I wasn't able to access those specific events through the associations
specified in the model. Given
r = Record.first, when I tried to
access the audition, by using
r.test, Rails would use a SQL query
that would correspond to
After acknowledging that, I turned to @varandas and we both thought it might
be a bug in the Rails framework. Turns out it wasn't; all I had to do was
belongs_to (thanks @drogus!). The reason for that is the
foreign key is on the
records table. From the framework's
perspective, it looks like the record actually belongs to the event,
when in practice it's not.