简体   繁体   English

Datamapper ORM保存和更新不起作用

[英]Datamapper orm save and update not working

Please Help me out I am using data mapper v1.8.2.1 请帮帮我,我正在使用数据映射器v1.8.2.1

my ledger table is having child staff table 我的总账表有孩子职员表

$l = new Ledger();
$l->where('id', $id)->get();
$l->name = 'john';

$s = new Staff();
$s->first_name = 'john';
$s->last_name = 'doe';

$l->save($l);

nothing is save by this code 此代码不保存任何内容

i tried 我试过了

$s->save($l);

also nothing is saved 也什么也没有保存

  1. At first try: 首先尝试:

     $l->save($s); 
  2. If this will not work, check relationship setup between the models. 如果这不起作用,请检查模型之间的关系设置。 They should be set in both models: 应当在两个模型中都设置它们:

     class Ledger extends DataMapper { var $has_many = array("staff"); } class Staff extends DataMapper { var $has_one = array("ledger"); } 
  3. In your database, table staffs should have column ledger_id, which has to be set as a foreign key to field id in ledgers (note that table names are plural). 在您的数据库中,表人员应具有ledger_id列,必须将其设置为分类账中字段id的外键(请注意,表名是复数)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM