I just run fixtures normally, and some of them need depends, but the execution don't respect the order
namespace common\fixtures\formgenerator;
/**
* Fixture to load `SolicitudeValue` records.
*/
class SolicitudeValueFixture extends \tecnocen\formgenerator\fixtures\SolicitudeValueFixture
{
/**
* @inheritdoc
*/
public $dataFile = '@common/fixtures/data/formgenerator/SolicitudeValue.php';
/**
* @inheritdoc
*/
public $depends = [
'common\fixtures\formgenerator\FieldFixture',
'common\fixtures\formgenerator\SolicitudeFixture',
'common\fixtures\formgenerator\SectionFixture'
];
}
The expected result is Execute FieldFixture, SolicitudFixture and SectionFixture before SolicitudValueFixture, but it doesn't happen, so SolicitudValue fails because it has foreign keys with the other tables.
In console I get this
12. formgenerator/DataType
13. formgenerator/SolicitudeValue
14. formgenerator/SectionField
15. formgenerator/FieldRule
16. formgenerator/FieldRuleProperty
17. formgenerator/Solicitude
18. formgenerator/Section
19. formgenerator/Field
20. formgenerator/Form
| Q | A
| ---------------- | ---
| Yii version | 2.0.12
| PHP version | 5.6.30-12
| Operating system | Xubuntu 16.04.1
My test (d81fa0a) for this issue shows that fixtures are loaded in the correct order:
Build was successful: https://travis-ci.org/yiisoft/yii2/builds/475090986
I used the following fixture for the test:
class DependentActiveFixture extends ActiveFixture
{
public $modelClass = 'yiiunit\data\ar\Customer';
public $depends = [
'yiiunit\data\console\controllers\fixtures\FirstIndependentActiveFixture',
'yiiunit\data\console\controllers\fixtures\SecondIndependentActiveFixture',
];
}
But if turn on output, you can see the following picture in the console during the tests:
Fixtures below will be loaded:
...
2. DependentActive
...
5. SecondIndependentActive
6. FirstIndependentActive
...
So:
Most likely the problem is in the data output in the method FixtureController::actionLoad():
https://github.com/yiisoft/yii2/blob/a140b2b46884003f7aea61b9ad1cf1b61f68c937/framework/console/controllers/FixtureController.php#L109-L167
Researched a bit. The order of fixtures in the console output depends on the order in which the fixture files were found: https://github.com/yiisoft/yii2/blob/a140b2b46884003f7aea61b9ad1cf1b61f68c937/framework/console/controllers/FixtureController.php#L396-L425
Well, of course this order does not correlate with the order in which fixtures are really loaded...
It think it could be adjusted to match real loading order.
Thanks for research @rugabarbo.