From 2534f208cf09837330aea1bf4b835ce17611cdd8 Mon Sep 17 00:00:00 2001 From: Franz Liedke <249125+franzliedke@users.noreply.github.com> Date: Fri, 22 Mar 2024 15:32:05 +0100 Subject: [PATCH] README: Update example ActiveRecord model In order to use the model to `find` individual records, the primary key must be explicitly defined. At least that's my experience with PostgreSQL. Also, see https://arjanvandergaag.nl/blog/view-backed-activerecord-models.html --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index a67db0fa..7b798347 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,11 @@ no different than a table. class SearchResult < ApplicationRecord belongs_to :searchable, polymorphic: true + # If you want to be able to call +Model.find+, you + # must declare the primary key. It can not be + # inferred from column information. + # self.primary_key = :id + # this isn't strictly necessary, but it will prevent # rails from calling save, which would fail anyway. def readonly?