$finder = sfPropelFinder::from('Category c')->
  select(array('c.Id', 'c.Name'), sfModelFinder::ASSOCIATIVE);
$categories = $finder->find();
$t->is($finder->getLatestQuery(), propel_sql('SELECT [P12category.ID, ]category.ID AS "c.Id", category.NAME AS "c.Name" FROM category'), 'select(array) accepts complete column names with table aliases');
$cat1 = array_shift($categories);
$t->is_deeply(array_keys($cat1), array('c.Id', 'c.Name'), 'Each row returned by find() after select(array) is an associative array where the keys are the requested complete column names with table aliases');

$finder = sfPropelFinder::from('Category')->
  select(array('Id','Name'));
$categories = $finder->find();
$cat1 = array_shift($categories);
$t->is_deeply(array_keys($cat1), array('Id', 'Name'), 'select(array) uses the associative mode by default');

$foo1 = new Foo();
$foo1->setReallylongcolumnnameforassoctesting('long1');
$foo1->save();

// fix for a bug/limitation in pdo_dblib where it truncates columnnames to a maximum of 31 characters when doing PDO::FETCH_ASSOC
$finder = sfPropelFinder::from('Foo')->
  select(array('Foo.Reallylongcolumnnameforassoctesting'));
$foo = $finder->findOne();
$t->is_deeply($foo, array('Foo.Reallylongcolumnnameforassoctesting' => 'long1'), 'select() does not mind long column names');

/********************************************************/
/* sfPropelFinder::select(array, sfModelFinder::SIMPLE) */
/********************************************************/

$t->diag('sfPropelFinder::select(array, sfModelFinder::SIMPLE)');

ArticlePeer::doDeleteAll();
CategoryPeer::doDeleteAll();
示例#2
0
 public function testDoubleReference()
 {
     $x = new Foo();
     $x->x = 1;
     $x->bar = new Foo();
     $x->save();
     $this->assertTrue(getconnection()->getCollection('Foo')->is($x->bar));
 }
 public function testTxnQo()
 {
     $tx_cnx = $this->getCnxForTxn();
     # begin a new cnx
     $tx_cnx->beginTxn();
     # create and save a foo on our new cnx
     $foo = new Foo();
     $foo->_setDb($tx_cnx);
     $foo->name = "sean";
     $foo->save();
     $tx_foo = Foo::Q($tx_cnx)->getById($foo->id)->exec();
     $this->assertEquals($foo->name, $tx_foo->name);
     $notx_foo = Foo::Q()->getById($foo->id)->exec();
     $this->assertTrue(empty($notx_foo));
     $tx_cnx->commitTxn();
     $notx_foo = Foo::Q()->getById($foo->id)->exec();
     $this->assertEquals($foo->name, $notx_foo->name);
 }
示例#4
0
 public function testRetrieveWithManyImplicit()
 {
     $thing = new Thing();
     $thing->name = 'mything';
     $thing->save();
     $foo = new Foo();
     $foo->name = 'sean';
     $foo->save();
     $thing->associateWith($foo);
     $foo = new Foo();
     $foo->name = 'sammy';
     $foo->save();
     $thing->associateWith($foo);
     $thing = new Thing($thing->id);
     $thing->retrieve();
     $foos = $thing->foos;
     $this->assertTrue(is_array($foos));
     $this->assertEquals('sean', $foos[0]->name);
     $this->assertEquals('sammy', $foos[1]->name);
 }
示例#5
0
文件: EntityTest.php 项目: cyve/orm
echo "Foo::find(null, array('name' => 'desc'));";
var_dump(Foo::find(null, array('name' => 'desc')));
echo "Foo::find(1);";
var_dump(Foo::find(1));
echo "Foo::find(array('name' => 'bar'));";
var_dump(Foo::find(array('name' => 'bar')));
echo "Foo::count(array('name' => 'bar'));";
var_dump(Foo::count(array('name' => 'bar')));
echo "Foo::find(array('name' => 'ba%'));";
var_dump(Foo::find(array('name' => 'ba%')));
echo "Foo::find(null, null, 1);";
var_dump(Foo::find(null, null, 1));
echo '<hr>';
$foo = new Foo(null, 'miam');
var_dump($foo->isNew());
$foo->save();
$foo = Foo::find($foo->id);
var_dump($foo);
$foo->name = 'miam 2';
$foo->save();
$foo = Foo::find($foo->id);
var_dump($foo);
$foo->delete();
$foo = Foo::find($foo->id);
var_dump($foo);
echo '<hr>';
$property = new ReflectionProperty('Foo', 'em');
$property->setAccessible(true);
$property->setValue(null);
$property = new ReflectionProperty('Foo', 'table');
$property->setAccessible(true);