Skip to content

Instantly share code, notes, and snippets.

@mmiliaus
Last active December 19, 2015 01:19
Show Gist options
  • Save mmiliaus/5875347 to your computer and use it in GitHub Desktop.
Save mmiliaus/5875347 to your computer and use it in GitHub Desktop.
<?php
// find record by ID
$article = Doctrine_Core::getTable('Article')->find(123);
// set multi attributes in one go
$article->fromArray(array(
'Title' => 'My first article',
'Content' => 'This is my very first article.\n Hope you enjoy it!',
));
// Query interface
// execute() - fetch all records
// fetchOne() - to fetch just a single record
$q = Doctrine_Core::getTable('Comment')
->createQuery('c')
->where('c.author = ?', 'Steve')
->leftJoin('c.Article a')
->andWhere('a.content LIKE ?', '%enjoy%')
->orderBy('c.created_at ASC');
$comments = $q->execute();
// raw SQL
$connection = Doctrine_Manager::connection();
$query = 'SELECT MAX(created_at) AS max FROM blog_article';
$statement = $connection->execute($query);
$statement->execute();
$resultset = $statement->fetch(PDO::FETCH_OBJ);
$max = $resultset->max;
// Join with table, that has no Relation
$q = new Doctrine_RawSql();
$categories = $q
->select('{c.*}')
->from('
category c
left join temp_user_categories uc ON uc.category_id = c.id
')
->addComponent('c', 'Category c')
->where('c.type = ?', self::CATEGORY_TYPE_DB)
->orderBy('uc.is_active DESC, c.position')
->execute();

Module

./symfony doctrine:generate-module frontend job JobeetJob

Doctrine Migrations

Migrating Up

  • Update config/doctrine/schema.yml
  • ./symfony doctrine:generate-migrations-diff - only a migration for the new change will get created
  • ./symfony doctrine:migrate - migrate all the pending migrations

Migrating Down

  • ./symfony doctrine:migrate --down - migrate one migration down
  • ./symfony doctrine:migrate N-22 - migrate to version "22"

Building Models, Forms & Filters

./symfony doctrine:build --all-classes

Additional Info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment