-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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