-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3.0] Single entity flush #1139
Conversation
Implemented! |
Why does it need changing? The behavior is documented this way. I am not sure this is a problem to flush the new entities as well, however your solution requires yet another state array inside UoW, making the management much more complex. |
I have this usecase: class City {
public $id; // pk
public $name;
}
// 1st case
$rome = new City();
$rome->name = "rome";
$em->persist($rome);
$milan = new City();
$milan->name = "milan";
$em->persist($milan);
$em->flush($rome);
// "milan" is flushed to the database... why?
// this case is in contradiction with previous one
$rome = findByName('rome');
$rome->name = "rome1";
$em->persist($rome);
$milan = findByName('milan');
$milan->name = "mailan1";
$em->persist($milan);
$em->flush($rome);
// now, "milan" is not flushed to the database... 2nd case class City {
public $id; // pk
public $name;
}
class Building {
public $id; // pk
public $name;
public $city; // not null
}
function findOrCreateCity($name){
$city = findCityByName($name);
if ($city){
$city = new City();
$city->name = $name;
$em->persist($city);
$em->flush($city);
}
return $city;
}
$building = new Building();
$building->name = 'Palace';
$em->persist($building);
// note, $building->city has NOT NULL constraint,
// and $building has been already persisted, but not flushed
$building->city = findOrCreateCity('rome');
// note, flush() call is not present here
This happens when |
The added complexity to UoW of course is a bad thing, and i will try to find a better solution, but this does not change my point of view in |
Looking at this test, https://github.com/doctrine/doctrine2/blob/master/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php#L1056
|
Here are my thoughts on this:
I think we should just drop this API completely for 3.x: instead, what we could eventually do is providing some API for manually populating |
f17b3df
to
fda6ff3
Compare
Hi 😄 I have rebased this on top of the latest master. Any chance to fix this |
Related to #6118 |
After much discussion, |
Is there going to be a way to flush a single object, or the feature has been just removed? |
Nevermind, just checked the related tickets |
Arg.... You are too fast :)) |
The current
flush
behavior seems to be inconsistent or not well documented.If i have understood the documentation in the correct way,
flush($entity)
should flush the passed entity (and its related associations/entities), and leave untouched the remaining object graph.The current behavior seems to be: flush all new objects, flush all
$entity
"updates", clear all "todo" stored into current UnitOfWork state.