top-think / top-think/think-orm
主键问题
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 437
- Forks
- 188
- PR merge metrics
- No merged PRs in 30d
Description
多对多关联,插入数据,主键没有设置成功
在User模型onBeforeInsert里主动设置了id
$structure = Structure::find($structureId);
$structure->users()->save($userData);
user表插入数据成功,但是id插入为空。
如果使用User::create($userData),插入数据,id设置成功
Contributor guide
No contributing guide indexed for this repository
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
Reproduce the case using the User model's onBeforeInsert hook, Structure::find($structureId), and the structure's users()->save($userData) path. Compare it with User::create($userData) and trace where the primary key is handled during the many-to-many save. Done means the association path persists the explicitly assigned User id, with a regression test covering both paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100