feat(curd): 关联表优化支持 add relation support and optimize model associations

- Add support for handling relations in CURD operations
- Optimize model associations to use hasOne instead of belongsTo
- Implement field selection for relations
- Update controller to handle AJAX requests and return JSON data Modify model to include relation methods
This commit is contained in:
wolfcode
2025-04-16 15:28:41 +08:00
parent d513177c74
commit 3a2ee69d0f
5 changed files with 41 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
public function {{relationMethod}}()
{
return $this->belongsTo('{{relationModel}}', '{{foreignKey}}', '{{primaryKey}}');
return $this->hasOne({{relationModel}}, '{{foreignKey}}', '{{primaryKey}}'){{relationFields}};
}