Filter on a non related entity

30 views
Skip to first unread message

mirza.dnc...@gmail.com

unread,
Aug 29, 2014, 5:39:13 AM8/29/14
to symfony2adm...@googlegroups.com
Hi,
I have a question about the filter process. So here is my problem :

I'm using the adminGenerator for a Contact entity. I have a Segment entity which I use to create segments of contacts and other entities...
Contact and segment entities are not really  related, I use some metadatas in the segment to retrieve the right entity when I'm showing a segment.

Is it possible to add a "virtual" column, segment, in the generator.yml and return all the contacts that returns the segment ?

I tried with :

params:

fields:
  segment:
        dbType: entity
        data_class:     Dnc\DemoBundle\Entity\Segment

builders:
  filters:
        params:
            display: [ companyName, firstName, lastName, email, type, segment ]


I get the following error :

An exception has been thrown during the rendering of a template ("No mapping found for field 'segment' on class 'Dnc\DemoBundle\Entity\Contact'.") in ListBuilderAction.php.twig at line 129.


Any help would be appreciated,
Thanks

Cédric Lombardot

unread,
Aug 29, 2014, 6:01:56 AM8/29/14
to Symfony2 Admingenerator bundles support for users
Hi,

Have you try filterOn option ? 

fields:
   segment:
      filter_on segment.name

Cedric


--
--
You received this message because you are subscribed to the Google
Groups "Symfony2 Admingenerator bundles support for users" group.
To post to this group, send email to
symfony2adm...@googlegroups.com
To unsubscribe from this group, send email to
symfony2admingene...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony2admingenerator?hl=en
 
---
Found bundle documentation at http://symfony2admingenerator.org/

---
You received this message because you are subscribed to the Google Groups "Symfony2 Admingenerator bundles support for users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to symfony2admingene...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mirza.dnc...@gmail.com

unread,
Aug 29, 2014, 6:31:36 AM8/29/14
to symfony2adm...@googlegroups.com
I just tried it, I get the same error.

I have no relation between Contact and Segment so the admingenerator doesn't know segment
Is it possible to put somewhere a function name that returns a queryBuilder so the filterAction can use it even if it's not a field of Contact ?

For more options, visit this group at
http://groups.google.com/group/symfony2admingenerator?hl=en
 
---
Found bundle documentation at http://symfony2admingenerator.org/

---
You received this message because you are subscribed to the Google Groups "Symfony2 Admingenerator bundles support for users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to symfony2admingenerator+unsub...@googlegroups.com.

Cédric Lombardot

unread,
Aug 29, 2014, 9:11:48 AM8/29/14
to Symfony2 Admingenerator bundles support for users
Yes of course you can override each generated methods see in your cache folder to see how the controller (ListController) is built you will find the good place to override just write the new version of your function in your own controller



For more options, visit this group at
http://groups.google.com/group/symfony2admingenerator?hl=en
 
---
Found bundle documentation at http://symfony2admingenerator.org/

---
You received this message because you are subscribed to the Google Groups "Symfony2 Admingenerator bundles support for users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to symfony2admingene...@googlegroups.com.

mirza.dnc...@gmail.com

unread,
Sep 1, 2014, 9:24:27 AM9/1/14
to symfony2adm...@googlegroups.com
Ok, thank you Cédric !

The solution I found to add a virtual column is the filter is to override formBuilder and add manually a virtual column and override some methods in the ListController such
- getPager to accept joined tables
- processFilters where I add my custom filters. In my case, I called a method that returns a QueryBuilder object.
- buildQuery, I just changed the alias so I had the same alias in the query

Hope it helps someone else.
By the way, the AdminGenerator is a great tool !! It saves a lot of time !! =)

For more options, visit this group at
http://groups.google.com/group/symfony2admingenerator?hl=en
 
---
Found bundle documentation at http://symfony2admingenerator.org/

---
You received this message because you are subscribed to the Google Groups "Symfony2 Admingenerator bundles support for users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to symfony2admingenerator+unsubscri...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages