Walter, I am going to look into that PR. I had this issue with pre-loading whether I had id as a primary key there at all or not (primary_key: true or primary_key: false), and it didn’t work.
However, setting self.primary_key = :post_id or even to :id (if primary_key is true) worked! So, I guess my particular issue is that ActiveRecord can’t pick up the primary key from a view (even if it is present and is called id).
Again, thanks for helping, and I think while the referenced PR is about a different issue, it deserves consideration indeed.
It depends on your DB engine, but views don’t really have primary keys in the normal sense of the word. When ActiveRecord calls DESCRIBE 'foos' to get the table details, it can’t tell which column is primary from that, and so it just doesn’t set one. Long ago, before the war, there was a final fallback in AR that said “if you can’t figure out which is the PK, and there’s a column named exactly ‘id’, then use that”. That hasn’t been true since sometime in Rails 5’s lifetime.