wintercms / wintercms/winter

RecordFinder fails to recognize parent_id field in models using NestedTree trait

Open
#1,341 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs review
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

  1. Create a model that uses the NestedTree trait (e.g., ProductCategory)
  2. Add the necessary database fields (parent_id, nest_left, nest_right, nest_depth)
  3. Define parent and children relationships in the model
  4. Configure a form with a RecordFinder field type to select parent_id
  5. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.