DEV Community

Discussion on: Rails 5.2.x --> Rails 6 counter_cache Gotcha

Collapse
 
asciigeek profile image
asciigeek

In most other ORM’s, in other frameworks, it is common to change those relationships using the entire object and not just setting the foreign key relationship with a primary key of a parent object. Clearly, rails has decided to go down that same avenue and it makes sense.

A proper framework should result in identically performing SQL whether you were specific in .where shelf_id: = shelf.id

or

.where shelf:=shelf

In the second case, the framework would understand that the primary key of shelf is ‘id’ and only utilize that one column in the query.