function _createCourse()
 {
     $course = new CourseForTest();
     $course->setTitle('General Course');
     $course->save();
     return $course;
 }
 function _createCourseWithTwoLectures()
 {
     $course = new CourseForTest();
     $course->setTitle($title = 'General Course');
     $l1 = new LectureForTest();
     $l1->setTitle('Physics');
     $l2 = new LectureForTest();
     $l2->setTitle('Math');
     $course->addToLectures($l1);
     $course->addToLectures($l2);
     $course->save();
     return $course;
 }
 function testFetch_Attach_RelatedHasMany_WithCriteriaForAttach()
 {
     $course1 = $this->creator->createCourse();
     $course2 = $this->creator->createCourse();
     $lecture1 = $this->creator->createLecture($course1, null, 'ZZZ');
     $lecture2 = $this->creator->createLecture($course2, null, 'CCC');
     $lecture3 = $this->creator->createLecture($course1, null, 'AAA');
     $query = lmbARQuery::create('CourseForTest', array(), $this->conn);
     $arr = $query->eagerAttach('lectures', array('criteria' => lmbSQLCriteria::equal('title', 'CCC')))->fetch()->getArray();
     $this->conn->resetStats();
     $this->assertIsA($arr[0], 'CourseForTest');
     $this->assertEqual($arr[0]->getTitle(), $course1->getTitle());
     $lectures = $arr[0]->getLectures();
     $this->assertEqual(count($lectures), 0);
     $this->assertIsA($arr[1], 'CourseForTest');
     $this->assertEqual($arr[1]->getTitle(), $course2->getTitle());
     $lectures = $arr[1]->getLectures();
     $this->assertEqual(count($lectures), 1);
     $this->assertEqual($lectures[0]->getId(), $lecture2->getId());
     $this->assertEqual($lectures[0]->getTitle(), 'CCC');
     $this->assertEqual($this->conn->countQueries(), 0);
     // let's change the first course and save it. The lectures should stay in database
     $arr[0]->setTitle('Changed');
     $arr[0]->save();
     $loaded_course = new CourseForTest($course1->getId());
     $lectures = $loaded_course->getLectures();
     $this->assertEqual(count($lectures), 2);
 }
 function createCourse($program = null)
 {
     $course = new CourseForTest();
     $course->setTitle('Course_' . rand(0, 100));
     if ($program) {
         $course->setProgram($program);
     }
     $course->save();
     return $course;
 }
 protected function _initCourse($lectures = array())
 {
     $course = new CourseForTest();
     $course->setTitle('Course' . mt_rand());
     if (count($lectures)) {
         foreach ($lectures as $lecture) {
             $course->addToLectures($lecture);
         }
     }
     return $course;
 }
 function testCorrectUsageCrossRelations()
 {
     $program = new ProgramForTest();
     $program->setTitle('Program');
     $program->save();
     $course = new CourseForTest();
     $course->setProgram($program);
     $course->save();
     $lecture = new LectureForTest();
     $lecture->setCourse($course);
     $lecture->setCachedProgram($program);
     $lecture->save();
     try {
         $finded_lectures = $program->getCachedLectures()->find(array('join' => array('course')))->getArray();
     } catch (lmbException $e) {
         $this->assertTrue(false);
     }
 }
 function testGettingCollectionDoesntMakeObjectDirty()
 {
     $course = new CourseForTest();
     $lectures = $course->getLectures();
     $this->assertFalse($course->isDirty());
 }
 function testImportWhereOne2ManyParentIsObject()
 {
     $course = new CourseForTest();
     $course->setTitle('Some course');
     $l = new LectureForTest();
     $l->setTitle('Physics');
     $l->setCourse($course);
     $l->save();
     $source = array('title' => $l->getTitle(), 'course' => $course);
     $l2 = new LectureForTest();
     $l2->import($source);
     $this->assertEqual($l2->getTitle(), $l->getTitle());
     $this->assertEqual($l2->getCourse()->getTitle(), $course->getTitle());
 }