Skip to content

Commit

Permalink
README: Update example ActiveRecord model
Browse files Browse the repository at this point in the history
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
  • Loading branch information
franzliedke authored and derekprior committed Mar 28, 2024
1 parent b371800 commit 2534f20
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit 2534f20

Please sign in to comment.