tags:

views:

10

answers:

0

i am starting out with doctrine as created a test page. i have a OneToMany relationship between User and Entry. the problem i am having is on 1st request, it creates the objects, checked the database tables - OK, but the output, doctrine didnt return any entries, it did correctly on users tho ... until i refresh the page again - it added duplicate users as i didnt change the names. but still, the just inserted entries are not detected until yet another refresh.

$user1 = new \EntitiesUser;
$user1->setName("user 1");
$em->persist($user1);

$entry1 = new \Entities\Entry;
$entry1->title = "Entry 1";
$entry1->body = "Body 1";
$entry1->user = $user1;
$em->persist($entry1);

$entry2 = new \Entities\Entry;
$entry2->title = "Entry 2";
$entry2->body = "Body 2";
$entry2->user = $user1;
$em->persist($entry2);

$query = $em->createQuery('select u from Entities\User u join u.entries e');
$users = $query->getResult();
?>

<ul>
    <?php foreach ($users as $user) : ?>
    <li>
        <h3><?php echo "[" . $user->getId() . "]" . $user->getName(); ?></h3>
        <ul>
            <?php foreach ($user->getEntries() as $entry) : ?>
            <li><?php echo "[$entry->id]" . $entry->title; ?></li>
            <?php endforeach; ?>
        </ul>
    </li>
    <?php endforeach; ?>
</ul>

i have a video on it on screenr