Mam dwie strony (User i UserPreferences), które chcę odwzorować OneToOne jednokierunkowo.Kaskada Doctrine2.3 i OneToOne wydaje się nie działać
Kod wygląda mniej więcej tak:
/**
* @ORM\Table("users")
* @ORM\Entity
*/
class User
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
*/
protected $id;
...
/**
* @ORM\Column(name="user_preferences_id", type="integer")
* @ORM\OneToOne
* (
* targetEntity="UserPreferences",
* cascade={"persist"}
*)
*/
protected $userPreferences;
public function __construct() {
$this->userPreferences = new UserPreferences();
}
}
/**
* @ORM\Table("user_preferences")
* @ORM\Entity
*/
class UserPreferences extends UserPreferencesEntity
{
/**
* @ORM\Id
* @ORM\Column(name="user_id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
...
}
Teraz kiedy tworzony jest nowy użytkownik, PreferencjeUżytkownika jest inicjowany z nowym PreferencjeUżytkownika sprzeciwu. Gdy próbuje się utrzymywać user
, Doktryna zgłasza wyjątek, twierdząc
A new entity was found through the relationship '...\Entity\User#userPreferences' that was not configured to cascade persist operations for entity: ...\Entity\[email protected] To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}).
ale co jeszcze trzeba zrobić? User # userPreferences jest skonfigurowany tak, aby kaskadowo działał, ale tak się nie dzieje. Czy coś tu jest nie tak?
Czy próbowałeś już bez tej właściwości adnotacji? – Flosculus
Bez której właściwości adnotacji? – dwalldorf