Skip to content

Instantly share code, notes, and snippets.

@wowkin2
Last active January 13, 2016 16:24
Show Gist options
  • Save wowkin2/f01e0dbbec8962dc3d2d to your computer and use it in GitHub Desktop.
Save wowkin2/f01e0dbbec8962dc3d2d to your computer and use it in GitHub Desktop.
Python/Django vs. PHP/Symfony
// ### PHP / Symfony2 / ORM ###/
// create new document
$product = new Product();
$product->setName('A Foo Bar');
$product->setPrice('19.99');
$product->setDescription('Lorem ipsum dolor');
$em = $this->getDoctrine()->getManager();
$em->persist($product);
$em->flush();
// query for one product matching by name and price
$product = $repository->findOneBy(
array('name' => 'foo', 'price' => 19.99)
);
// query for all products matching the name, ordered by price
$products = $repository->findBy(
array('name' => 'foo'),
array('price' => 'ASC')
);
### Python / Django / MongoEngine ###
// create new document (mongoengine)
product = Product()
product.name = 'A Foo Bar'
product.price = 19.99
product.description = 'Lorem ipsum dolor'
product.save()
// or
product = Product(
name='A Foo Bar',
price=19.99,
description='Lorem ipsum dolor',
).save()
// query for one product matching by name and price
product = Product.objects(
name='foo', price=19.99
).first()
// query for all products matching the name, ordered by price
products = Product.objects(
name='foo'
).sort('price')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment