protected function _getExistingRecords($objects)
 {
     $table = new lmbTableGateway($this->relation_info['table'], $this->conn);
     $criteria = new lmbSQLCriteria();
     $criteria->addAnd(new lmbSQLFieldCriteria($this->relation_info['field'], $this->owner->getId()));
     $criteria->addAnd(new lmbSQLFieldCriteria($this->relation_info['foreign_field'], null, lmbSQLFieldCriteria::IS_NOT_NULL));
     $existing_records = $table->select($criteria);
     return lmbCollection::toFlatArray($existing_records, $this->relation_info['foreign_field']);
 }
 function testRemoveAllDeletesOnlyProperRecordsFromTable()
 {
     $group1 = $this->_initGroup();
     $group2 = $this->_initGroup();
     $user = new UserForTestWithSpecialRelationTable();
     $user->setFirstName('User' . mt_rand());
     $user->save();
     $collection = new lmbARManyToManyCollection('groups', $user);
     $collection->add($group1);
     $collection->add($group2);
     $db_table = new lmbTableGateway('extended_user_for_test2group_for_test');
     $db_table->insert(array('user_id' => $user->getId(), 'other_id' => 100));
     $collection->removeAll();
     $this->assertEqual($db_table->select()->count(), 1);
 }