Another fix

1 view
Skip to first unread message

Luís Otávio

unread,
Dec 22, 2009, 8:09:03 AM12/22/09
to outle...@googlegroups.com
Hi all,

I think that you'll hate me hahahah

When using one-to-may relation the OutletMapper::saveOneToMany() method is saving the relations in a right way, but it do not update the Colletion after the children's inserts, so the Colletion has no *_OutletProxy objects.

The code that I think we have to change is that:

$foreignEntityCfg = $this->config->getEntity($foreign);
foreach ($children->getArrayCopy() as $child) {
    /** @todo make it work with composite keys */
    $foreignEntityCfg->setProp($child, $key, current($pks));
    $this->save($child);
}

$obj->$setter($children);

We can fix it doing:

$foreignEntityCfg = $this->config->getEntity($foreign);
$newArr = array();
foreach ($children->getArrayCopy() as $child) {
    /** @todo make it work with composite keys */
    $foreignEntityCfg->setProp($child, $key, current($pks));
    $this->save($child);
    $newArr[] = $child;
}

$children->exchangeArray($newArr);
$obj->$setter($children);


That's it!

Luís

Fabio R.

unread,
Dec 23, 2009, 12:28:04 AM12/23/09
to outle...@googlegroups.com
Hi Luís,

Using trunk I wasn't able to reproduce the error.

Would you be able to write an unit test using entities from our test suite or provide us some more info about the bug? (config file, entities definition and usage code)


Cheers,
--
Fábio Rehm


--

You received this message because you are subscribed to the Google Groups "Outlet ORM" group.
To post to this group, send email to outle...@googlegroups.com.
To unsubscribe from this group, send email to outlet-orm+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/outlet-orm?hl=en.

Luís Otávio

unread,
Dec 23, 2009, 6:38:31 AM12/23/09
to outle...@googlegroups.com
Hello,
 
I'll send the files, and maybe at night the unit tests.
 
Luís

Luís Otávio

unread,
Dec 23, 2009, 10:29:34 AM12/23/09
to outle...@googlegroups.com
Hi there,

Here are the files, in usage.php I've put a lot of var_dump's to get the object state.

Before the patch:

object(Pessoa_OutletProxy)#16 (6) {
  ["id:private"]=>
  string(1) "1"
  ["nome:private"]=>
  string(4) "Luis"
  ["enderecoId:private"]=>
  NULL
  ["endereco:private"]=>
  NULL
  ["dataCriacao:private"]=>
  object(Calendar)#14 (1) {
    ["time:private"]=>
    string(19) "23/12/2009 13:25:03"
  }
  ["cartoes:private"]=>
  object(OutletCollection)#18 (1) {
    [0]=>
    object(Cartao)#13 (3) {
      ["numero:private"]=>
      NULL
      ["senha:private"]=>
      string(32) "9ed8ae108f082f3da33e84157a791a76"
      ["pessoaId:private"]=>
      int(1)
    }
  }
}
object(Pessoa_OutletProxy)#16 (6) {
  ["id:private"]=>
  string(1) "1"
  ["nome:private"]=>
  string(4) "Luis"
  ["enderecoId:private"]=>
  NULL
  ["endereco:private"]=>
  NULL
  ["dataCriacao:private"]=>
  object(Calendar)#14 (1) {
    ["time:private"]=>
    string(19) "23/12/2009 13:25:03"
  }
  ["cartoes:private"]=>
  object(OutletCollection)#18 (2) {
    [0]=>
    object(Cartao_OutletProxy)#20 (3) {
      ["numero:private"]=>
      string(1) "1"
      ["senha:private"]=>
      string(32) "88d658c86c60ce493bcb734ebc00987e"
      ["pessoaId:private"]=>
      int(1)
    }
    [1]=>
    object(Cartao)#11 (3) {
      ["numero:private"]=>
      NULL
      ["senha:private"]=>
      string(32) "9ed8ae108f082f3da33e84157a791a76"
      ["pessoaId:private"]=>
      int(1)
    }
  }
}
object(Pessoa_OutletProxy)#16 (6) {
  ["id:private"]=>
  string(1) "1"
  ["nome:private"]=>
  string(4) "Luis"
  ["enderecoId:private"]=>
  NULL
  ["endereco:private"]=>
  NULL
  ["dataCriacao:private"]=>
  object(Calendar)#14 (1) {
    ["time:private"]=>
    string(19) "23/12/2009 13:25:03"
  }
  ["cartoes:private"]=>
  object(OutletCollection)#18 (3) {
    [0]=>
    object(Cartao_OutletProxy)#20 (3) {
      ["numero:private"]=>
      string(1) "1"
      ["senha:private"]=>
      string(32) "88d658c86c60ce493bcb734ebc00987e"
      ["pessoaId:private"]=>
      int(1)
    }
    [1]=>
    object(Cartao)#11 (3) {
      ["numero:private"]=>
      NULL
      ["senha:private"]=>
      string(32) "9ed8ae108f082f3da33e84157a791a76"
      ["pessoaId:private"]=>
      int(1)
    }
    [2]=>
    object(Cartao)#12 (3) {
      ["numero:private"]=>
      NULL
      ["senha:private"]=>
      string(32) "9ed8ae108f082f3da33e84157a791a76"
      ["pessoaId:private"]=>
      int(1)
    }
  }
}


After:

object(Pessoa_OutletProxy)#16 (6) {
  ["id:private"]=>
  string(1) "1"
  ["nome:private"]=>
  string(4) "Luis"
  ["enderecoId:private"]=>
  NULL
  ["endereco:private"]=>
  NULL
  ["dataCriacao:private"]=>
  object(Calendar)#14 (1) {
    ["time:private"]=>
    string(19) "23/12/2009 13:26:54"
  }
  ["cartoes:private"]=>
  object(OutletCollection)#18 (1) {
    [0]=>
    object(Cartao_OutletProxy)#20 (3) {
      ["numero:private"]=>
      string(1) "1"
      ["senha:private"]=>
      string(32) "9ed8ae108f082f3da33e84157a791a76"
      ["pessoaId:private"]=>
      int(1)
    }
  }
}
object(Pessoa_OutletProxy)#16 (6) {
  ["id:private"]=>
  string(1) "1"
  ["nome:private"]=>
  string(4) "Luis"
  ["enderecoId:private"]=>
  NULL
  ["endereco:private"]=>
  NULL
  ["dataCriacao:private"]=>
  object(Calendar)#14 (1) {
    ["time:private"]=>
    string(19) "23/12/2009 13:26:54"
  }
  ["cartoes:private"]=>
  object(OutletCollection)#18 (2) {
    [0]=>
    object(Cartao_OutletProxy)#20 (3) {
      ["numero:private"]=>
      string(1) "1"
      ["senha:private"]=>
      string(32) "88d658c86c60ce493bcb734ebc00987e"
      ["pessoaId:private"]=>
      int(1)
    }
    [1]=>
    object(Cartao_OutletProxy)#15 (3) {
      ["numero:private"]=>
      string(1) "2"
      ["senha:private"]=>
      string(32) "9ed8ae108f082f3da33e84157a791a76"
      ["pessoaId:private"]=>
      int(1)
    }
  }
}
object(Pessoa_OutletProxy)#16 (6) {
  ["id:private"]=>
  string(1) "1"
  ["nome:private"]=>
  string(4) "Luis"
  ["enderecoId:private"]=>
  NULL
  ["endereco:private"]=>
  NULL
  ["dataCriacao:private"]=>
  object(Calendar)#14 (1) {
    ["time:private"]=>
    string(19) "23/12/2009 13:26:54"
  }
  ["cartoes:private"]=>
  object(OutletCollection)#18 (3) {
    [0]=>
    object(Cartao_OutletProxy)#20 (3) {
      ["numero:private"]=>
      string(1) "1"
      ["senha:private"]=>
      string(32) "88d658c86c60ce493bcb734ebc00987e"
      ["pessoaId:private"]=>
      int(1)
    }
    [1]=>
    object(Cartao_OutletProxy)#15 (3) {
      ["numero:private"]=>
      string(1) "2"
      ["senha:private"]=>
      string(32) "9ed8ae108f082f3da33e84157a791a76"
      ["pessoaId:private"]=>
      int(1)
    }
    [2]=>
    object(Cartao_OutletProxy)#21 (3) {
      ["numero:private"]=>
      string(1) "3"
      ["senha:private"]=>
      string(32) "9ed8ae108f082f3da33e84157a791a76"
      ["pessoaId:private"]=>
      int(1)
    }
  }
}

As you can see the objects inside the collection (before the correction) are from Cartao class and not Cartao_OutletProxy.

Luís
Teste-Outlet.tar.gz
Reply all
Reply to author
Forward
0 new messages