/** * Save and then read from the database * * This needs to be used in order to do things like use {@link add()} on a newly created * object. This could be done automatically, but it is not in all circumstances that * it would be necessary, so the option is given to the developer as to whether or not * a database read is necessary after a database save. * * The reason this is required is that, in order to optimise memory usage of the system, * a DbObject never stores any data in memory. Rather, it holds a reference to a * {@link Query} object and an index. It then uses the relevant 'seeking' function * (eg. mysql_data_seek) for the underlying RDBMS to get data when requested. Because * of this, if you create a new object and set field values, then try to add objects * to it it will attempt to read from the database, but because no clause is set the * results will be unexpected. * * Thus, if you are creating and saving a new object, you will not have to perform * a database read operation, but if you want to, say, create a new Author and then * add some books to it, you would need something like: * * <code> * $auth = new Author(); * $auth->parse(); * $auth->synch(); * * foreach($this->newBooks() as $book) * $auth->add($book); * * $auth->save(); * </code> * * @access public * @see save,read */ public function synch() { $this->save(); $this->setClause($this->uniqueClause()); $query = $this->loadQuery(); $query->doQuery(); $this->reset(); $this->table->setQuery($query, 0); $this->requires_insert = false; }