user1236048
user1236048

Reputation: 5602

How can I orderby in schema.yml doctrine symfony 1.4

I've got a many to many relationship from Project to Asset using ProjectAsset class as middle class between this 2. When I use getProjectAsset() method on a project it returns all my ProjectAssets assigned to that project.

How can I change the schema.yml to order the results by default?

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

Upvotes: 2

Views: 4622

Answers (2)

GergelyPolonkai
GergelyPolonkai

Reputation: 6421

This is my first thought after reading http://www.dobervich.com/2011/03/05/symfony2-blog-application-tutorial-part-ii-the-data-model/ Haven't tested yet, though.

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

Upvotes: 15

Attila Fulop
Attila Fulop

Reputation: 7011

It doesn't have to be done in schema.yml file but when retrieving the data in the code.

Eg.

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

Update: Maybe you can: check this question.

Upvotes: 2

Related Questions