RecordFinder fails to recognize parent_id field in models using NestedTree trait
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 1.5k
- Forks
- 246
- Avg merge
- 19h 2m
- Merged PRs (30d)
- 7
Description
Discussed in https://github.com/orgs/wintercms/discussions/1339
Originally posted by fleixweb April 18, 2025
Description
When using the RecordFinder form widget with a model that implements the NestedTree trait, the system incorrectly reports that the 'parent_id' field does not exist in the model, even though the field is properly defined in the database table and included in the model's $fillable array.
Steps to Reproduce
- Create a model that uses the NestedTree trait (e.g., ProductCategory)
- Add the necessary database fields (parent_id, nest_left, nest_right, nest_depth)
- Define parent and children relationships in the model
- Configure a form with a RecordFinder field type to select parent_id
- Attempt to create or edit a record
Expected Behavior
The RecordFinder should properly recognize the parent_id field and allow selection of a parent record.
Actual Behavior
The system displays an error: "Model '[Namespace][ModelName]' does not contain 'parent_id'."
Workaround
Replacing the RecordFinder with a Dropdown field type and implementing a getParentIdOptions() method in the model resolves the issue.
Technical Details
Winter CMS version: [Winter CMS 1.2.0]
PHP version: [PHP 8.2.26]
Database: MySQL [MySQL 8.0.40]
Suggested Fix
Modify the RecordFinder component to properly recognize and handle the parent_id field when used with the NestedTree trait. This would allow developers to use both features together without conflict.
Additional Context
This issue specifically occurs at the intersection of two Winter CMS features: the RecordFinder form widget and the NestedTree trait. Both work fine independently, but fail when used together to manage hierarchical relationships within the same model.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the RecordFinder form widget and the model's NestedTree trait, then reproduce the reported parent_id validation error using a model with the listed tree fields and relationships. Done means RecordFinder accepts parent_id and allows selecting a parent record without requiring the Dropdown workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- laravel, php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100