我可以通过引用保存新的相关对象,而无需在 Kohana 3 的 ORM 中手动复制 id 吗?
我有 2 个对象。球员和比赛。 Player 是 Match 的子级。我想知道是否可以同时创建这两个而不需要手动插入 id。
ie
$match = ORM::factory('match');
$player1 = ORM::factory('player');
$player2 = ORM::factory('player');
$player1->match = $match;
$player2->match = $match;
$match->save();
$player1->save();
$player2->save();
类似于 Ruby 中的 ActiveRecord
I have 2 objects. Player and Match. Player is a child of Match. I want to know if I can create both of these at the same time without inserting id's manually.
i.e.
$match = ORM::factory('match');
$player1 = ORM::factory('player');
$player2 = ORM::factory('player');
$player1->match = $match;
$player2->match = $match;
$match->save();
$player1->save();
$player2->save();
Similar to ActiveRecord in Ruby
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如下:
请注意,按关系设置时应使用 saved ORM 对象。
附言。你们的关系好吗?一个玩家可以参加很多场比赛,所以我更喜欢另一种方案:
Here is it:
Note that you should use saved ORM object when setting it by relationship.
PS. Is your relationship right? One player can play a lot of matches, so I'd preffer another scheme: