Skip to content

fix(associations): read singular ids key for has_many in frontmatter - #229

Open
pcbeingused333 wants to merge 2 commits into
Rails-Designer:mainfrom
pcbeingused333:fix/has-many-singular-ids
Open

pcbeingused333 wants to merge 2 commits into
Rails-Designer:mainfrom
pcbeingused333:fix/has-many-singular-ids

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

has_many ignored the documented editor_ids frontmatter key and returned an empty collection.

has_many built the frontmatter key as "#{association_name}_ids" (editors_ids), but the docs (resources.md) and the skill template use the Rails convention (editor_ids, comment_ids). With the documented key the lookup never matched, fell back to foreign key matching and returned an empty collection without any warning.

Fix: look up the singular _ids key first and keep the plural one as a fallback, so existing content keeps working. The docs sentence is updated to name the singular form.

Also: records_for_ids did it[:id], which raises NoMethodError on a Perron::Resource target (the documented has_many :comments example). It now compares ids as strings against the record's id metadata, falling back to the slug for Resources.

Tests: in associations_test.rb: editor_ids resolves data records (red before the change), editors_ids still works, and ids resolve against a Resource class by slug (red before: NoMethodError).


This change was prepared with the help of an AI coding assistant (Claude) and submitted by a human who is responsible for it.

has_many looked only for the pluralised key (editors_ids), but the docs use the Rails convention (editor_ids), so the collection silently fell back to the foreign key and came back empty. Accept the singular key first and keep the plural one as a fallback.
@eelcoj

eelcoj commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

The singular-key fix is good; please drop the id_for/Resource additions (it is an undocumented, out-of-scope feature)

Keeps the singular ids key fix only, as requested in review.
@pcbeingused333

Copy link
Copy Markdown
Contributor Author

Done: removed the id_for helper and the Resource-by-slug matching (plus the extra reviewers association and its test). records_for_ids is back to its original form; the PR now only reads the singular *_ids key (keeping the plural as fallback), with the docs line and tests for both keys.

(Drafted with Claude Code; not run locally by the author.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants