nextras / orm

Orm with clean object design, smart relationship loading and powerful collections.
https://nextras.org/orm
MIT License
310 stars 57 forks source link

Adding entity into relationship loads all entities during the second persist. #184

Closed hrach closed 8 years ago

hrach commented 8 years ago

Due to e5365fcf4bce7f66fed6bdd836e99a89bcd6c3e9 we load the whole collection during the second relationship. However, such behavior may lead to loading very extensive collection.

Example:

/**
  * @property Street[] $streets {1:m Street::$country}
  */
class Country ... {}

/**
 * @property Country $country {m:1 Country::$streets}
 */
class Street ... {}

$country->streets->add(new Street());

// will same new Street & set wasLoaded to true
// https://github.com/nextras/orm/blob/v2.1.1/src/Relationships/OneHasMany.php#L40
$model->persist($country); 

// the repeated call will load entire collections of streets
$model->persist($country);
JanTvrdik commented 8 years ago

probably related to https://github.com/nextras/orm/pull/172

f3l1x commented 7 years ago

:+1: