Looking at your code, I don't think I would have done things any
differently. If I need better performance I might look a little closer
to see if I can avoid re-adding OrderLines that already existed. Even
then I would probably still use the repository to do that, since I don't
think there's any way the ORM can take care of it for you.
What modifications were necessary to achieve this? Are you talking about
the unit-of-work?
Thanks,
Alvaro
Thanks,
Alvaro
Fabio wrote:
> My bad, I mixed everything up....
>
> One of the things you already answered, the other 2 are the things I
> mentioned in the last message about the composite key and the identity
> map.
>
> What I've chaged in the library was one thing that I don't know if it
> is classified as a bug but here we go:
>
> OutletMapper.php
> private function saveOneToMany () {
> $conf = Outlet::getInstance()->getConfig()->getEntity($this->cls);
>
> $return = true; // this line
>
> foreach ($conf->getAssociations() as $assoc) {
> if ($assoc->getType() != 'one-to-many') continue;
>
> $key = $assoc->getKey();
> $getter = $assoc->getGetter();
> $setter = $assoc->getSetter();
>
> $children = $this->obj->$getter(null);
> if (sizeof($children) == 0) continue; // I added this line because
I'm not sure why the line above was added. What would happen if there's
more than one 'one-to-many' association?
> foreach ($children as &$child) {
> $child->$key = $this->getPK();
>
> $mapped = new self($child);
> if ($mapped->isNew()) {
>
> $return = $mapped->save() && $return; // this line
>
> }
> }
>
> $this->obj->$setter( $children );
> }
>
>
> return $return; // this line
Was returning a boolean here necessary for your implementation of
unit-of-work? Assuming database errors throw exceptions, when would you
expect false?
> }
>
> I also had to add a 'return $this->saveOneToMany()' on the last line
> of insert().
>
> I don't know if I did the right way but what I think is that the
> save() method is not returning true when everything works fine, I
> think I solved the insert() method but the update() is looking the
> same since there is no 'return'.
>
> I'm using the files on /trunk
> See ya,
> Fabio
>
Thanks for your feedback and good catch on the identity map stuff.
Alvaro