RedBeanPHP\Repository::store PHP Method

store() public method

If the database schema is not compatible with this bean and RedBean runs in frozen mode it will throw an exception. This function returns the primary key ID of the inserted bean. The return value is an integer if possible. If it is not possible to represent the value as an integer a string will be returned. We use explicit casts instead of functions to preserve performance (0.13 vs 0.28 for 10000 iterations on Core i3).
public store ( redbeanphp\OODBBean | redbeanphp\SimpleModel $bean ) : integer | string
$bean redbeanphp\OODBBean | redbeanphp\SimpleModel bean to store
return integer | string
    public function store($bean)
    {
        $processLists = $this->hasListsOrObjects($bean);
        if (!$processLists && !$bean->getMeta('tainted')) {
            return $bean->getID();
            //bail out!
        }
        $this->oodb->signal('update', $bean);
        $processLists = $this->hasListsOrObjects($bean);
        //check again, might have changed by model!
        if ($processLists) {
            $this->storeBeanWithLists($bean);
        } else {
            $this->storeBean($bean);
        }
        $this->oodb->signal('after_update', $bean);
        return (string) $bean->id === (string) (int) $bean->id ? (int) $bean->id : (string) $bean->id;
    }

Usage Example

示例#1
0
 /**
  * Stores a bean in the database. This method takes a
  * OODBBean Bean Object $bean and stores it
  * in the database. If the database schema is not compatible
  * with this bean and RedBean runs in fluid mode the schema
  * will be altered to store the bean correctly.
  * If the database schema is not compatible with this bean and
  * RedBean runs in frozen mode it will throw an exception.
  * This function returns the primary key ID of the inserted
  * bean.
  *
  * The return value is an integer if possible. If it is not possible to
  * represent the value as an integer a string will be returned. We use
  * explicit casts instead of functions to preserve performance
  * (0.13 vs 0.28 for 10000 iterations on Core i3).
  *
  * @param OODBBean|SimpleModel $bean bean to store
  *
  * @return integer|string
  */
 public function store($bean)
 {
     $bean = $this->unboxIfNeeded($bean);
     $id = $this->repository->store($bean);
     if (self::$autoClearHistoryAfterStore) {
         $bean->clearHistory();
     }
     return $id;
 }
All Usage Examples Of RedBeanPHP\Repository::store