本文整理匯總了PHP中Propel\Runtime\Collection\ObjectCollection::save方法的典型用法代碼示例。如果您正苦於以下問題:PHP ObjectCollection::save方法的具體用法?PHP ObjectCollection::save怎麽用?PHP ObjectCollection::save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Propel\Runtime\Collection\ObjectCollection
的用法示例。
在下文中一共展示了ObjectCollection::save方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testWithPaginate
public function testWithPaginate()
{
QuerycacheTable1Query::create()->deleteAll();
$coll = new ObjectCollection();
$coll->setModel('\\Propel\\Tests\\Bookstore\\Behavior\\QuerycacheTable1');
for ($i = 0; $i < 5; $i++) {
$b = new QuerycacheTable1();
$b->setTitle('Title' . $i);
$coll[] = $b;
}
$coll->save();
$pager = $this->getPager(2, 1);
$this->assertEquals(5, $pager->getNbResults());
$results = $pager->getResults();
$this->assertEquals('query cache with paginate offset 0 limit 2', $pager->getQuery()->getQueryKey());
$this->assertEquals(2, count($results));
$this->assertEquals('Title1', $results[1]->getTitle());
//jump to page 3
$pager = $this->getPager(2, 3);
$this->assertEquals(5, $pager->getNbResults());
$results = $pager->getResults();
$this->assertEquals('query cache with paginate offset 4 limit 2', $pager->getQuery()->getQueryKey());
$this->assertEquals(1, count($results));
$this->assertEquals('Title4', $results[0]->getTitle());
}
示例2: testSaveOnReadOnlyEntityThrowsException
/**
* @expectedException \Propel\Runtime\Exception\PropelException
*/
public function testSaveOnReadOnlyEntityThrowsException()
{
$col = new ObjectCollection();
$col->setModel('\\Propel\\Tests\\Bookstore\\ContestView');
$cv = new ContestView();
$col[] = $cv;
$col->save();
}
示例3: createBooks
protected function createBooks($nb = 15, $con = null)
{
BookQuery::create()->deleteAll($con);
$books = new ObjectCollection();
$books->setModel('\\Propel\\Tests\\Bookstore\\Book');
for ($i = 0; $i < $nb; $i++) {
$b = new Book();
$b->setTitle('Book' . $i);
$books[] = $b;
}
$books->save($con);
}
示例4: insertChunk
/**
* @param string $itemType
* @param string $itemEvent
* @param array $itemIds
*
* @return int
*/
protected function insertChunk($itemType, $itemEvent, array $itemIds)
{
$propelCollection = new ObjectCollection();
$propelCollection->setModel(SpyTouch::class);
foreach ($itemIds as $itemId) {
$touchEntity = new SpyTouch();
$touchEntity->setItemEvent($itemEvent)->setItemId($itemId)->setItemType($itemType)->setTouched(new \DateTime());
$propelCollection->append($touchEntity);
}
$propelCollection->save();
return $propelCollection->count();
}
示例5: testFromArray
public function testFromArray()
{
$author = new Author();
$author->setFirstName('Jane');
$author->setLastName('Austen');
$author->save();
$books = array(array('Title' => 'Mansfield Park', 'ISBN' => 'FA404', 'AuthorId' => $author->getId()), array('Title' => 'Pride And Prejudice', 'ISBN' => 'FA404', 'AuthorId' => $author->getId()));
$col = new ObjectCollection();
$col->setModel('Propel\\Tests\\Bookstore\\Book');
$col->fromArray($books);
$col->save();
$nbBooks = PropelQuery::from('Propel\\Tests\\Bookstore\\Book')->count();
$this->assertEquals(6, $nbBooks);
$booksByJane = PropelQuery::from('Propel\\Tests\\Bookstore\\Book b')->join('b.Author a')->where('a.LastName = ?', 'Austen')->count();
$this->assertEquals(2, $booksByJane);
}
示例6: save
public function save($key = null)
{
if ($key === null) {
$data = [];
foreach (array_keys($this->preferences) as $key) {
$data[] = $this->getPreference($key);
}
$collection = new ObjectCollection($data);
$collection->setModel(PreferenceTableMap::CLASS_NAME);
$collection->save();
} else {
if ($this->has($key)) {
$p = $this->getPreference($key);
$p->save();
}
}
}
示例7: populateCreatedAt
protected function populateCreatedAt()
{
Table2Query::create()->deleteAll();
$ts = new ObjectCollection();
$ts->setModel('\\Propel\\Tests\\Bookstore\\Behavior\\Table2');
for ($i = 0; $i < 10; $i++) {
$t = new Table2();
$t->setTitle('CreatedAt' . $i);
$t->setCreatedAt(time() - $i * 24 * 60 * 60 - 30);
$ts[] = $t;
}
$ts->save();
}