add handling of array type in data loader #110

Merged
merged 4 commits into from Feb 23, 2012

Projects

None yet

2 participants

Member
havvg commented Feb 21, 2012

Allow handling of ARRAY column type to load fixtures like:

\Acme\BlogBundle\Model\User:
    admin:
        username: 'admin'
        salt: 'ee99a5169df885207981a45c73274a01'
        password: '4ha2s+HXiayiBuekr0xTnAAAgD6YHHvwWd65LzboQYzYWLkW1/BT9Oj6F6TczffxaMiaWynCPy0bkRDcwH/R9w=='
        roles: [ ROLE_ADMIN ]
Member
havvg commented Feb 21, 2012

The "dump" works fine somehow, it dumps the stored string: roles: '| ROLE_ADMIN |'

Owner

mmh, we should fix the dump then? Because, even if it works, it's not consistent..

Member
havvg commented Feb 22, 2012

True.

Member
havvg commented Feb 23, 2012

@willdurand Good to go?

Owner

Nope. I would like to have the same behavior in data dumper.

Le 23 févr. 2012 à 22:00, Toni Uebernickelreply@reply.github.com a écrit :

@willdurand Good to go?


Reply to this email directly or view it on GitHub:
#110 (comment)

Member
havvg commented Feb 23, 2012

It's there at 82170e1 :-)

@willdurand willdurand commented on an outdated diff Feb 23, 2012
DataFixtures/Loader/AbstractDataLoader.php
@@ -161,10 +161,19 @@ protected function loadDataFromArray($data = null)
}
foreach ($data as $name => $value) {
- if (is_array($value) && 's' == substr($name, -1)) {
- // many to many relationship
- $this->loadManyToMany($obj, substr($name, 0, -1), $value);
- continue;
+ try {
+ if (is_array($value) && 's' == substr($name, -1)) {
+ // many to many relationship
+ $this->loadManyToMany($obj, substr($name, 0, -1), $value);
+ continue;
+ }
+ } catch (\PropelException $e) {
+ // Check whether this is actually an array stored in the object.
+ if ('Cannot fetch TableMap for undefined table: '.substr($name, 0, -1) === $e->getMessage()) {
+ if ($tableMap->getColumn($name)->getType() !== 'ARRAY') {
willdurand
willdurand Feb 23, 2012 Owner

should be:

if ('ARRAY' !== $tableMap->getColumn($name)->getType()) {
@willdurand willdurand commented on an outdated diff Feb 23, 2012
DataFixtures/Loader/AbstractDataLoader.php
@@ -161,10 +161,19 @@ protected function loadDataFromArray($data = null)
}
foreach ($data as $name => $value) {
- if (is_array($value) && 's' == substr($name, -1)) {
- // many to many relationship
- $this->loadManyToMany($obj, substr($name, 0, -1), $value);
- continue;
+ try {
+ if (is_array($value) && 's' == substr($name, -1)) {
willdurand
willdurand Feb 23, 2012 Owner

What about using a strict equality here?

Owner

Oups sorry, I was kind of… away from GitHub.

Please, review my comments, and merge this PR for me ;)

@havvg havvg merged commit c4459e6 into propelorm:2.0 Feb 23, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment