Sonata admin export problem

3,641 views
Skip to first unread message

Xavi Corral

unread,
Jul 4, 2012, 1:16:25 PM7/4/12
to sonat...@googlegroups.com
Hi ,

we have a problem with the sonata admin export feature. we have a basic entity, Home, and a one-to-many related entity Currency storing the currency in which the prices will be held:

Home.php:

/*
    * @ORM\ManyToOne(targetEntity="
Front\PropertyBundle\Entity\Currency", cascade={"persist"})
    * @ORM\JoinColumn(name="currency_id", referencedColumnName="id", unique=false)
    */
    protected $currency;


Currency.php:

    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @var string $name
     *
     * @ORM\Column(name="name", type="string", length=30, nullable=true)
     */
    protected $name;



this field is not mandatory while inserting a new home, so many homes in the table have the currency_id column  set to null

when selecting fields to export:

HomeAdmin.php:

    public function getExportFields()
    {
        return array(
                'currency.name',
                ...
        );
    }


the export fails when homes without currency appear in the list, we get this exception:

Expected argument of type "object or array", "NULL" given

in /var/www/sites/dev.rentamosya.com.mx/vendor/symfony/src/Symfony/Component/Form/Util/PropertyPath.php at line 202

watching inside the code, we see the features uses the DoctrineORMQuerySourceIterator.php, which for everyfield expects an array or an object, and in our case null is given since the field not filled

thanks a lot in advance for your help

Sergio Moya

unread,
Jul 5, 2012, 6:52:23 AM7/5/12
to sonat...@googlegroups.com
Same problem.

Im waiting for this PR.

https://github.com/sonata-project/exporter/pull/5

diszo

unread,
Aug 16, 2012, 3:55:43 AM8/16/12
to sonat...@googlegroups.com
Hi everyone,

I manage to solved this problem.
It's just a hack but here's what i did.

add the following on your <Module>Admin.php class:

public function getExportFields()
    {
        $results = $this->getModelManager()->getExportFields($this->getClass()); 

        // Need to add again our foreign key field here
        $results[] = 'category';  <--- category is the name of the field FK to category table that I want to include. 

        return $results;
    }


That's It!

Good luck! :)

mell zamora

unread,
Sep 10, 2012, 7:43:21 PM9/10/12
to sonat...@googlegroups.com
Nice!

Xurudragon

unread,
Sep 13, 2013, 4:54:25 AM9/13/13
to sonat...@googlegroups.com
Hi,

I did what you said, but it did nothing to change my problem ...

I still have the same error << "object or array" "Null" given ... >>

Because my FK can be null, sonata do not check if the data was null or not and try to access to the property of my FK table ...

Anyone have a suggestion for me to resolve my problem?

Thank you in advance,

Best regards,

Xurudragon

Phil Smithson

unread,
Dec 8, 2013, 12:13:49 AM12/8/13
to sonat...@googlegroups.com
Thanks Diszo :D


On Thursday, August 16, 2012 3:55:43 PM UTC+8, diszo wrote:

Francis Angelino Gonzales Tello

unread,
Mar 12, 2014, 10:54:44 AM3/12/14
to sonat...@googlegroups.com
How about custom format dates? to exportFields?

Saif Rehman

unread,
May 2, 2018, 10:14:30 AM5/2/18
to sonata-devs
how can we customize the whole query?
Reply all
Reply to author
Forward
0 new messages