Jordan Warbelow-Feldstein
Jordan Warbelow-Feldstein

Reputation: 10748

Ordered Many-Many Relationship in Doctrine?

Attempting to link Categories to Websites, using WebsiteCategory as the refClass.

WebsiteCategory has a column rank, which indicates the order in which the categories should be retrieved when you call $website->getCategories()

I'm stumped, didn't think this would be so difficult. Can anyone help?

Upvotes: 2

Views: 1255

Answers (3)

Charles
Charles

Reputation: 166

This is not supported for Many to Many relationships, the bug report is linked below with a possible patch, although some comments indicate it was not working. As already noted by OP, I think the solution is to override the getCategories() function.

http://www.doctrine-project.org/jira/browse/DC-651

Upvotes: 1

Jordan Warbelow-Feldstein
Jordan Warbelow-Feldstein

Reputation: 10748

Was not able to get doctrine to order the relationship natively (like Damien was suggesting) instead, added a getCategories() function to the model which runs the proper query and returns the result set.

Upvotes: 1

Damien
Damien

Reputation: 5882

You can add an orderBy param in your schema.yml:

Gallery:
  columns:
    title: string(255)
  relations:
    Images:
      local: id
      foreign: gallery_id
      foreignAlias: Gallery
      type: many
      orderBy: position DESC

You can put multi fields with a comma.

Upvotes: 0

Related Questions