Example #1
0
 public function __construct()
 {
     $dbParams = array('dbname' => 'demo', 'memory' => 'true', 'driver' => 'pdo_sqlite');
     $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . '/Model'), true);
     $this->entityManager = EntityManager::create($dbParams, $config);
     $tool = new SchemaTool($this->entityManager);
     $tool->createSchema($this->entityManager->getMetadataFactory()->getAllMetadata());
     // Create data
     $article = new Article(1);
     $category = new Category(1);
     $article->setCategory($category);
     $category->addArticle($article);
     $this->entityManager->persist($article);
     $this->entityManager->persist($category);
     $article = new Article(2);
     $this->entityManager->persist($article);
     $this->entityManager->flush();
 }
$category1->setName('cat1');
$category1->save();
$category2 = new Category();
$category2->setName('cat2');
$category2->save();
$article1 = new Article();
$article1->setTitle('art1');
$article1->setCategory($category1);
$article1->save();
$article2 = new Article();
$article2->setTitle('art2');
$article2->setCategory($category2);
$article2->save();
$article3 = new Article();
$article3->setTitle('art3');
$article3->setCategory($category1);
$article3->save();

$finder = sfPropelFinder::from('Article')->
  withColumn('Article.Title')->
  select('Article.Title');
$title = $finder->findOne();
$t->is($finder->getLatestQuery(), propel_sql('SELECT [P12article.ID, ]article.TITLE AS "Article.Title" FROM article LIMIT 1'), 'select() can cope with a column added with withColumn()');
$t->is($title, 'art1', 'select() can cope with a column added with withColumn()');

$finder = sfPropelFinder::from('Article')->
  join('Category')->
  withColumn('Category.Name')->
  select(array('Article.Title', 'Category.Name'));
$row = $finder->findOne();
$t->is($finder->getLatestQuery(), propel_sql('SELECT [P12article.ID, ]category.NAME AS "Category.Name", article.TITLE AS "Article.Title" FROM article INNER JOIN category ON (article.CATEGORY_ID=category.ID) LIMIT 1'), 'find() does not request twice the columns added by way of withColumn() and select()');
 public function addArticle(Article $l)
 {
     $this->collArticles[] = $l;
     $l->setCategory($this);
 }
Example #4
0
$app = 'frontend';
$fixtures = 'fixtures/fixtures.yml';
if (!include(dirname(__FILE__).'/../bootstrap/functional.php'))
{
  return;
}

$browser = new sfTestFunctional(new sfBrowser());

ArticlePeer::doDeleteAll();
$category = CategoryPeer::doSelectOne(new Criteria());

foreach (range(1, 20) as $n)
{
  $article = new Article();
  $article->setTitle(sprintf('Article #%s', $n));
  $article->setCategory($category);
  $article->save();
}

$browser
  ->getAndCheck('pager', 'interfaces')

  ->with('response')->begin()
    ->checkElement('#pagerResults li', 10)

    ->checkElement('#pagerCount:contains(20)')
  ->end()
;