Skip to content

Why hasOne() is forcing update of related model? How to understand 1-1 relationships? #15685

Answered by quasipickle
aircodepl asked this question in Q&A
Discussion options

You must be logged in to vote

Whenever you save a model, relevant related models should be saved. That's not broken. I think the issue is how you're trying to disassociate the driver from the car. I don't know the details, but Phalcon does some magic behind-the-scenes to ensure the relationship connection, and I don't think setting the connecting column to null kills that connection. I think the standard way is to set car to null like:

$driver->car = null;
$driver->save();

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@aircodepl
Comment options

Answer selected by aircodepl
Comment options

You must be logged in to vote
1 reply
@aircodepl
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants