Symfony Filter not working

社会主义新天地 提交于 2019-12-13 05:48:46

问题


My schema:

Poster:
  actAs:
    Timestampable: ~
    Sluggable:
      fields:[name]
  columns:
    id:
      type: integer(4)
      autoincrement: true
      primary: true
    name:
      type: string(255)
      notnull: true
    filename:
      type: string(255)
      notnull: true
    approved:
      type: boolean(1)
      default: false
    start_date:
      type: date
      notnull: true
    end_date:
      type: date    
      notnull: true  
    user_id:
      type: integer(20)
      default: 1
  attributes:
    export: all
    validate: true
  relations:
    User:
      class: sfGuardUser
      local: user_id
      foreign: id
      type: one
      foreignType: many
      foreignAlias: Posters

I have a module poster generated by doctrine:generate-admin. In the list view, I see the filters for all the fields including start_date and end_date. Now, the problem is, that these two filters are not working as they should. e.g. I provided a range for Start Date and pressed filter, in the response page, I saw the SQL queries tab of the web debug toolbar but there I don't see any indication for constraining the query according to the provided constraint. I just see this:

SET NAMES 'UTF8'
0.00s, "doctrine" connection

SELECT COUNT(*) AS num_results FROM poster p
0.00s, "doctrine" connection

SELECT s.id AS s__id, s.first_name AS s__first_name, s.last_name AS s__last_name, s.email_address AS s__email_address, s.username AS s__username, s.algorithm AS s__algorithm, s.salt AS s__salt, s.password AS s__password, s.is_active AS s__is_active, s.is_super_admin AS s__is_super_admin, s.last_login AS s__last_login, s.created_at AS s__created_at, s.updated_at AS s__updated_at FROM sf_guard_user s
0.00s, "doctrine" connection

SELECT p.id AS p__id, p.name AS p__name, p.enabled AS p__enabled, p.layout AS p__layout, p.created_at AS p__created_at, p.updated_at AS p__updated_at, p.slug AS p__slug FROM place p
0.00s, "doctrine" connection

SELECT p.id AS p__id, p.name AS p__name, p.filename AS p__filename, p.approved AS p__approved, p.start_date AS p__start_date, p.end_date AS p__end_date, p.user_id AS p__user_id, p.created_at AS p__created_at, p.updated_at AS p__updated_at, p.slug AS p__slug FROM poster p LIMIT 10
0.00s, "doctrine" connection

SELECT s.id AS s__id, s.first_name AS s__first_name, s.last_name AS s__last_name, s.email_address AS s__email_address, s.username AS s__username, s.algorithm AS s__algorithm, s.salt AS s__salt, s.password AS s__password, s.is_active AS s__is_active, s.is_super_admin AS s__is_super_admin, s.last_login AS s__last_login, s.created_at AS s__created_at, s.updated_at AS s__updated_at FROM sf_guard_user s WHERE (s.id = '2') LIMIT 1

Now, as the Poster model is Timestampable, there is a created_at field. I tried to filter the results by giving a range to this field, and in the queries tab, I now see

SELECT COUNT(*) AS num_results FROM poster p WHERE p.created_at >= '2011-12-15 00:00:00' AND p.created_at <= '2011-12-24 23:59:59'

Is that a bug in symfony? Please help.

UPDATE: Ok, I did a little investigation and found that there is no corresponding addFieldNameColumnQuery function in BasePosterFilter.class.php. So again, is that default symfony behaviour or is that some bug?


回答1:


Symfony doesn't create any addFieldNameColumnQuery for Doctrine (or addFieldNameColumnCriteria for Propel), but simply fields are "mapped" trough own types (Number, Text, Boolean, Date, ForeignKey), as you see in getFields() of a BaseMyModelFormFilter class, assigning the right filter when an input filter is used.

Instead if you add a new field, say myfield, you have to create a function addMyfieldNameColumnQuery (or addMyfieldNameColumnCriteria) to allows Symfony to get and add the right sql filter.



来源:https://stackoverflow.com/questions/8502824/symfony-filter-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!