Начиная с 4.1, Rails автоматически обнаруживает обратную ассоциацию.
См. Примечания к выпуску https://guides.rubyonrails.org/4_1_release_notes.html
В вашем случае последняя родительская строка попадает в базу данных.за.Фактический SQL-запрос извлек дочерние элементы, поскольку, когда вы обращаетесь к ассоциации в консоли Rails и фактически не используете результат, он не кэшируется.
parent = Parent.find(foo)
# Fetches the parent:
# Parent Load (0.3ms) SELECT "parents".* FROM "parents" WHERE ...
children = parent.children
# Fetches all children:
# Child Load (1.0ms) SELECT "children".* FROM "children" WHERE ...
# the association has not been cached
children.loaded? # => false
# Will fetch children again and again ...
children
# Fetches all children:
# Child Load (1.0ms) SELECT "children".* FROM "children" WHERE ...
children
# Fetches all children:
# Child Load (1.0ms) SELECT "children".* FROM "children" WHERE ...
# until you really use them:
children.to_a
children.loaded? # => true
children
# Does not hit the database now
Таким образом, в вашем случае это был запрос к базе данных для детей.
parent = Parent.find(foo)
# Fetches the parent
children = parent.children
# Fetches all children
children.first.parent
# Fetches all children again, does not fetch parent as it is automatically inversed
child = children.first
# will not fetch the parent
child.parent