0

I'm wondering how to avoid having a circular reference in my symfony2.1 application. I have an entity like

customer (
  name
  addresses -- OneToMany
  currentAddress -- OneToOne )

and

address (
  street
  customer -- ManyToOne )

Now my fixtures won't load because it can't delete the customer because of the foreign key.

For performances' sake I would like to avoid having to add a getCurrentAddress() method on customer which would select in the addresses table.

Does anybody have a solution for that?

Thomas
  • 671
  • 7
  • 13

1 Answers1

1

Adding a getCurrentAddress() isn't such a performance issue.

This way, I'll avoid the circular reference and all the issues that come along with it.

In my situation, using an order by date in the doctrine annotation was enough:

// on customer entity : 
/** @ORM\OrderBy({"datemodified" = "DESC"}) */
private $addresses

public function getCurrentAddress()
{
    return $this->addresses[0];
}
Thomas
  • 671
  • 7
  • 13