Exemple #1
0
 public function index($id)
 {
     $user = User::read(1);
     $this->set(['var' => $user->name]);
 }
 public function testBelongsToManySave()
 {
     /*
     *	userからセーブ
     */
     $user1 = User::create(['name' => 'newUser']);
     $skill1 = Skill::create(['name' => 'newSkill']);
     $user1->Skill[] = $skill1;
     $this->assertEquals(true, $user1->save());
     /*
     *	本当に保存できたかreadで確認
     */
     $savedUser1Skill = Skill::read($user1->Skill[0]->id);
     $this->assertEquals('newSkill', $savedUser1Skill->name);
     $savedSkill1User = User::read($user1->id);
     $this->assertEquals('newUser', $savedSkill1User->name);
     /*
     *	skillからセーブ
     */
     $skill2 = Skill::create(['name' => 'newSkill']);
     $user2 = User::create(['name' => 'newUser']);
     $skill2->User[] = $user2;
     $this->assertEquals(true, $skill2->save());
     /*
     *	本当に保存できたかreadで確認
     */
     $savedSkill2User = User::read($skill2->User[0]->id);
     $this->assertEquals('newUser', $savedSkill2User->name);
     $savedUser2Skill = Skill::read($skill2->id);
     $this->assertEquals('newSkill', $savedUser1Skill->name);
 }