protected function saveTheChildren()
    {
        $toReload = [];

        if (isset($this->addedChildren)) {
            foreach ($this->addedChildren as $relation => $children) {
                $relationship = call_user_func([ $this, $relation ]);
                if ($relationship instanceof HasMany) {
                    $relationship->saveMany($children);
                } else {
                    throw new PropertySetterException(
                        "Relationship " . get_class($relationship) . " is not implemented yet."
                    );
                }

                // Also save the children
                foreach ($children as $child) {
                    if ($child instanceof Model) {
                        $child->saveTheChildren();
                    }
                }

                $toReload[$relation] = true;
            }
        }

        if (isset($this->removedChildren)) {
            foreach ($this->removedChildren as $relation => $children) {
                $relationship = call_user_func([ $this, $relation ]);

                if ($relationship instanceof HasMany) {

                    foreach ($children as $child) {
                        $child->delete();
                    }

                } else {
                    throw new PropertySetterException(
                        "Relationship " . get_class($relationship) . " is not implemented yet."
                    );
                }

                $toReload[$relation] = true;
            }
        }

        if (isset($this->editedChildren)) {
            foreach ($this->editedChildren as $relation => $children) {
                $relationship = call_user_func([ $this, $relation ]);

                foreach ($children as $child) {
                    if ($child instanceof Model) {
                        $child->saveRecursively();
                    } else {
                        $child->save();
                    }
                }

                $toReload[$relation] = true;
            }
        }

        $toReload = array_keys($toReload);
        foreach ($toReload as $reload) {
            unset($this->relations[$reload]);
        }
    }
protected function saveTheChildren()
    {
        $toReload = [];

        if (isset($this->addedChildren)) {
            foreach ($this->addedChildren as $relation => $children) {
                $relationship = call_user_func([ $this, $relation ]);
                if ($relationship instanceof HasMany) {
                    $relationship->saveMany($children);
                } else {
                    throw new PropertySetterException(
                        "Relationship " . get_class($relationship) . " is not implemented yet."
                    );
                }

                // Also save the children
                foreach ($children as $child) {
                    if ($child instanceof Model) {
                        $child->saveTheChildren();
                    }
                }

                $toReload[$relation] = true;
            }
        }

        if (isset($this->removedChildren)) {
            foreach ($this->removedChildren as $relation => $children) {
                $relationship = call_user_func([ $this, $relation ]);

                if ($relationship instanceof HasMany) {

                    foreach ($children as $child) {
                        $child->delete();
                    }

                } else {
                    throw new PropertySetterException(
                        "Relationship " . get_class($relationship) . " is not implemented yet."
                    );
                }

                $toReload[$relation] = true;
            }
        }

        if (isset($this->editedChildren)) {
            foreach ($this->editedChildren as $relation => $children) {
                $relationship = call_user_func([ $this, $relation ]);

                foreach ($children as $child) {
                    if ($child instanceof Model) {
                        $child->saveRecursively();
                    } else {
                        $child->save();
                    }
                }

                $toReload[$relation] = true;
            }
        }

        $toReload = array_keys($toReload);
        foreach ($toReload as $reload) {
            unset($this->relations[$reload]);
        }
    }
protected function saveTheChildren ( ) { $ toReload = [ ] ; if ( isset ( $ this -> addedChildren ) ) { foreach ( $ this -> addedChildren as $ relation => $ children ) { $ relationship = call_user_func ( [ $ this , $ relation ] ) ; if ( $ relationship instanceof HasMany ) { $ relationship -> saveMany ( $ children ) ; } else { throw new PropertySetterException ( "Relationship " . get_class ( $ relationship ) . " is not implemented yet." ) ; } // Also save the children foreach ( $ children as $ child ) { if ( $ child instanceof Model ) { $ child -> saveTheChildren ( ) ; } } $ toReload [ $ relation ] = true ; } } if ( isset ( $ this -> removedChildren ) ) { foreach ( $ this -> removedChildren as $ relation => $ children ) { $ relationship = call_user_func ( [ $ this , $ relation ] ) ; if ( $ relationship instanceof HasMany ) { foreach ( $ children as $ child ) { $ child -> delete ( ) ; } } else { throw new PropertySetterException ( "Relationship " . get_class ( $ relationship ) . " is not implemented yet." ) ; } $ toReload [ $ relation ] = true ; } } if ( isset ( $ this -> editedChildren ) ) { foreach ( $ this -> editedChildren as $ relation => $ children ) { $ relationship = call_user_func ( [ $ this , $ relation ] ) ; foreach ( $ children as $ child ) { if ( $ child instanceof Model ) { $ child -> saveRecursively ( ) ; } else { $ child -> save ( ) ; } } $ toReload [ $ relation ] = true ; } } $ toReload = array_keys ( $ toReload ) ; foreach ( $ toReload as $ reload ) { unset ( $ this -> relations [ $ reload ] ) ; } }
Save all related entities.
@throws PropertySetterException
Save all related entities .