Skip to content

Instantly share code, notes, and snippets.

@svandragt
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svandragt/ad3f543d680adc843a4b to your computer and use it in GitHub Desktop.
Save svandragt/ad3f543d680adc843a4b to your computer and use it in GitHub Desktop.
Basic testing problem
PHP Fatal error: Couldn't run query:
SELECT DISTINCT "IntakeType"."ClassName", "IntakeType"."Created", "IntakeType"."LastEdited", "IntakeType"."Title", "IntakeType"."Code", "IntakeType"."ID", CASE WHEN "IntakeType"."ClassName" IS NOT NULL THEN "IntakeType"."ClassName" ELSE 'IntakeType' END AS "RecordClassName"
FROM "IntakeType"
WHERE ("Code" = 'FIXED')
LIMIT 1
Table 'ss_tmpdb5256577.intaketype' doesn't exist in /vagrant/public_html/framework/model/MySQLDatabase.php on line 580
PHP Warning: Cookie 'alternativeDatabaseName' can't be set. The site started outputting content at line 64 in /vagrant/public_html/framework/dev/CliDebugView.php in /vagrant/public_html/framework/control/Cookie.php on line 35
PHP Warning: Cookie 'alternativeDatabaseNameIv' can't be set. The site started outputting content at line 64 in /vagrant/public_html/framework/dev/CliDebugView.php in /vagrant/public_html/framework/control/Cookie.php on line 35
<?php
class CourseDate extends DataObject {
public static $has_one = array(
'CourseMOA' => 'CourseMOA',
);
// code that uses coursemoa
}
<?php
class CourseDateTest extends SapphireTest {
public static $fixture_file = 'CourseDateTest.yml';
protected $extraDataObjects = array(
'CourseMOA',
'IntakeType'
);
public function testDelete() {
$this->assertTrue(true);
}
}
IntakeType:
fixed:
ID: 1
Title: Fixed
Code: FIXED
flexible:
ID:2
Title: Flexible
Code: FLEXIBLE
CourseMOA:
uno:
ID:3
IntakeType: =>IntakeType.fixed
CourseDate:
one:
CourseMOA: =>CourseMOA.uno
<?php
class CourseMOA extends DataObject
{
public static $has_one = array(
'IntakeType' => 'IntakeType',
);
public static $has_many = array(
'CourseDates' => 'CourseDate',
);
// [...]
public function populateDefaults()
{
parent::populateDefaults();
if (class_exists('IntakeType')) {
$IntakeTypeFixed = IntakeType::get()->filter('Code', 'FIXED');
if ($IntakeTypeFixed) {
$id = $IntakeTypeFixed->first()->ID;
$this->IntakeTypeID = $id;
}
}
}
}
@svandragt
Copy link
Author

@svandragt
Copy link
Author

yep, I tried changing to DataObject::get('IntakeType')... but that does not make a difference

@svandragt
Copy link
Author

DataQuery.php:165 $baseClass = $tableNames[0];

@svandragt
Copy link
Author

$i = IntakeType::get()->filter('Code', 'FIXED'); works ok because of lazy loading but when trying to get the ID then it still fails later.

@svandragt
Copy link
Author

Updated the CourseMOA.php with better code but still test fails the same.

@svandragt
Copy link
Author

Workaround / Solution:
Replace https://gist.github.com/svandragt/ad3f543d680adc843a4b#file-coursemoa-php-L18 with
if (class_exists('IntakeType') && (Security::database_is_ready())) {

Thanks @micmania

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment