【问题标题】:How can I orderby in schema.yml doctrine symfony 1.4我如何在 schema.yml 学说 symfony 1.4 中排序
【发布时间】:2012-03-13 12:59:20
【问题描述】:

我在项目和资产之间建立了多对多关系,使用 ProjectAsset 类作为这 2 之间的中间类。当我在项目上使用 getProjectAsset() 方法时,它会返回分配给该项目的所有 ProjectAsset。

如何更改 schema.yml 以默认对结果进行排序?

Project:
  relations:
    Assets:
      class: Asset
      refClass: ProjectAsset
      foreignAlias: Projects
      local: project_id
      foreign: asset_id           

ProjectAsset:
  tableName: projects_assets
  columns:
    title: { type: string, length: 255 }
    project_id:  { type: integer, primary: true }
    asset_id: { type: integer, primary: true }
  relations:
    Project:
      class: Project
      foreignAlias: ProjectAssetRelations
      local: project_id
      foreign: id
      onDelete: CASCADE
    Asset:
      class: Asset
      foreignAlias: ProjectAssetRelations
      local: asset_id
      foreign: id
      onDelete: CASCADE

【问题讨论】:

    标签: orm symfony1 doctrine schema many-to-many


    【解决方案1】:

    这是我阅读 http://www.dobervich.com/2011/03/05/symfony2-blog-application-tutorial-part-ii-the-data-model/ 后的第一个想法,不过还没有测试。

    oneToMany:
        posts:
            targetEntity: Post
            orderBy:
                createdAt: DESC
    

    【讨论】:

    • 感谢您的回答。这是一种无需使用查询构建器/标准等即可实现排序的简单方法!它甚至适用于嵌套实体列!干杯!
    • 这对我来说根本不起作用。我正在使用 Symfony 2.5
    【解决方案2】:

    不必在 schema.yml 文件中完成,而是在代码中检索数据时完成。

    例如。

    $passets = Doctrine_Query::create()
               ->select('p.*')
               ->from('ProjectAsset  p')
               ->orderBy("p.Title")
               ->execute();
    

    更新:也许你可以:check this question

    【讨论】:

      猜你喜欢
      • 2011-06-19
      • 1970-01-01
      • 1970-01-01
      • 2012-06-13
      • 2011-09-29
      • 1970-01-01
      • 1970-01-01
      • 2011-11-26
      • 1970-01-01
      相关资源
      最近更新 更多