Datamapper orm save and update not working

197 views Asked by At

Please Help me out I am using data mapper 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

There are 1 answers

0
maicher On
  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).