Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 252
user1236048 Avatar asked Dec 02 '25 05:12

user1236048


2 Answers

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
like image 73
GergelyPolonkai Avatar answered Dec 04 '25 22:12

GergelyPolonkai


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.

like image 21
Attila Fulop Avatar answered Dec 04 '25 22:12

Attila Fulop



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!