Closed attreid closed 4 years ago
Could you please elaborate more specifically what is the problem? When entity is persisted, the getCollection()
has actually a fresh data refresh here: https://github.com/nextras/orm/blob/f1aae3318765ded805bbc1b859cf4d8e0b5ea676/src/Relationships/HasMany.php#L279-L280
Ok I have simplified entity
/**
* @property string $id {primary}
* @property ManyHasMany|OtherEntity[] $others {m:m OtherEntity, isMain=true, oneSided=true}
*/
class MyEntity extends Entity {
}
When its created, its ok
$entity = new MyEntity();
$orm->myEntities->attach($entity);
$other = new OtherEntity();
// add some data
$entity->others->add($other);
foreach( $entity->others as $other){
// no problem, its here
}
$this->orm->persist($entity);
foreach( $entity->others as $other){
// its empty
}
And after flush is still empty
Is it the persist call running an sql query? Do you have correct mapping for relationship columns? There may be a bug, but I honestly hope that such basic behavior is well tested both with out tests and by Orm users. Will take a look later.
Persist call sql query correctly. This problem is only with new row in db. When row is exists and I call work with 'others' entity in foreach after persist, foreach correctly gets rows. And I forgot an important note. Its MsSql
Please, provide more info - e.g. a failing PR/zip with failing code. I cannot reproduce it. Will gladly reopen to fix it.
When Entity is persisted HasMany property does not contain entities (are pushed to variable tracked)
Is posible to add this to method getCollection in HasMany.php?