Reputation: 3923
In Doctrine i can do:
$article = Doctrine::getTable('Article')->createQuery('a')->where('a.user_id = ?', $this->getUser()->getAttribute('id') )->fetchOne()
and
$article = Doctrine::getTable('Article')->findBy('user_id', $this->getUser()->getAttribute('id'));
How can i make it in Propel? I use Symfony 1
Upvotes: 2
Views: 1134
Reputation: 3280
or for propel 1.6
ArticleQuery::create()
->filterByUserId($this->getUser()->getId())
->findOne();
//returns Article instance or null
or even
ArticleQuery::create()
->filterByUserId($this->getUser()->getId())
->findOneOrCreate();
//always returns article instance, if created user id will be already initialized
Upvotes: 2
Reputation: 823
Propel is pretty simple. I'm giving you a propel 1.4 answer. These look like the same query.
$article = Doctrine::getTable('Article')->createQuery('a')->where('a.user_id = ?', $this->getUser()->getAttribute('id') )->fetchOne()
$c = new Criteria;
$c->add(ArticlePeer::USER_ID, $this->getUser()->getId());
$article = ArticlePeer::doSelectOne($c);
Upvotes: 1