Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@doctrinebot
Created December 13, 2015 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doctrinebot/42476e78f6e5a04da901 to your computer and use it in GitHub Desktop.
Save doctrinebot/42476e78f6e5a04da901 to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-1149 - https://github.com/doctrine/doctrine2/issues/1749
<?php
set_include_path(implode(PATH_SEPARATOR, array(
__DIR__.'/Common/lib/',
__DIR__.'/doctrine2/lib/',
__DIR__.'/dbal/lib/',
get_include_path(),
)));
require 'Doctrine/Common/ClassLoader.php';
$autoloader = new \Doctrine\Common\ClassLoader('Doctrine');
$autoloader->register();
$doctrineConfig = new \Doctrine\ORM\Configuration;
$doctrineConfig->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$doctrineConfig->setProxyDir(__DIR__.'/proxies');
$doctrineConfig->setProxyNamespace('\Proxies');
$doctrineConfig->setAutoGenerateProxyClasses(true);
$doctrineConfig->setMetadataDriverImpl(
$doctrineConfig->newDefaultAnnotationDriver()
);
$connectionOptions = array(
'host' => 'localhost',
'dbname' => 'test',
'user' => 'root',
'password' => 'root',
'driver' => 'pdo_mysql'
);
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $doctrineConfig);
/**
* @Entity
* @Table(name="users")
*/
class User {
/**
* @Column
* @Id
*/
public $user_id;
/**
* @OneToMany(targetEntity="Post", mappedBy="user",fetch="EAGER")
*/
public $posts;
}
/**
* @Entity
* @Table(name="posts")
*/
class Post {
/**
* @Column
* @Id
*/
public $post_id;
/**
* @ManyToOne(targetEntity="User", inversedBy="posts")
* @JoinColumn(name="user_id", referencedColumnName="user_id")
*/
public $user;
}
$users = $em->getRepository('User')->findAll();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment