I have a Rails 3.2 app with a working scope based on a field in an associated model:

```
scope :maintenance, -> { joins(:costcat).where(costcats: { maintenance: true }) }

```

I would like the results to be ordered by `costcats.position`.

I tried these:

```
scope :maintenance, -> { joins(:costcat).where(costcats: { maintenance: true }).order(costcats.position ASC) }
scope :maintenance, -> { joins(:costcat).where(costcats: { maintenance: true }) }, :order => "costcats.position ASC"

```

Thanks for the help!

UPDATE1

With the suggested answers, I'm getting the following SQL:

```
SELECT "costestimates".* FROM "costestimates" INNER JOIN "costcats" ON "costcats"."id" = "costestimates"."costcat_id" WHERE "costestimates"."costproject_id" = 1 AND "costcats"."maintenance" = 't' ORDER BY id ASC, position ASC

```

It would work if the `id ASC` wasn't in the ORDER

UDDATE2

My bad, I had to remove the default scope order in `costestimates`