public function testOneToMany() { SolutionSchema::registerSchema("MySchema", "Rhubarb\\Stem\\Tests\\Fixtures\\UnitTestingSolutionSchema"); $company = new Company(); $company->getRepository()->clearObjectCache(); $company->CompanyName = "Test Company"; $company->save(); $user = new User(); $user->getRepository()->clearObjectCache(); $user->Username = "******"; $user->Password = "******"; $user->Active = 1; $user->CompanyID = $company->CompanyID; $user->save(); $user = new User(); $user->Username = "******"; $user->Password = ""; $user->Active = 1; $user->CompanyID = $company->CompanyID; $user->save(); $user = new User(); $user->Username = "******"; $user->Password = ""; $user->Active = 0; $user->CompanyID = $company->CompanyID; $user->save(); $oneToMany = new OneToMany("Unused", "Company", "CompanyID", "UnitTestUser"); $list = $oneToMany->fetchFor($company); $this->assertCount(2, $list); $this->assertEquals("msmith", $list[1]->Username); }
/** * Associates the models provided back to the model by way of their proper keys * * We use this time to also set a callback where we define our shifter. * * @param object|array $models A single model or array of models to associate * @param closure $callback A callback to potentially append additional data * @return object|array * @since 2.0.0 **/ public function associate($models, $callback = null) { $modelName = $this->model->getModelName(); $shifter = $this->shifter; parent::associate($models, function ($model) use($modelName, $shifter) { $model->set($shifter, strtolower($modelName)); }); return $models; }
public function initBySetting($model, $setting) { parent::initBySetting($model, $setting); if (is_array($setting)) { if (!isset($setting['table'])) { throw new \Stack\Exception\MissingSetting('"table" missing for the ManyToMany relation.'); } if (!isset($setting['remote_attribute_name'])) { throw new \Stack\Exception\MissingSetting('"remote_attribute_name" missing for the ManyToMany relation.'); } $this->table = $setting['table']; $this->remoteAttributeName = $setting['remote_attribute_name']; } }