views:

16

answers:

1

I have a simple models

class Item < ActiveRecord::Base
   has_many :parts
end
class Part < ActiveRecord::Base
   belongs_to :item
   default_scope :order => :index
end

Each part has it's own index, to be ordered inside of the Item in question.

When i load parts for the item in ItemsController.show method, the parts are not ordered.

This is what happens in db:

[4;35;1mPart Load (0.7ms)[0m   [0mSELECT "parts".* FROM "parts" WHERE ("parts".item_id = 165968587) [0m

Is't the "index" word reserved ?

Why ordering is not happens ?

+1  A: 

I'm not sure why that doesn't work, however you could also try something different:

class Item < ActiveRecord::Base
   has_many :parts,
            :order => :index
end
vise
Thanks, your suggestion works. But it only works, when i write it as: has_many :parts, :order => "\"index\"". Possible, "index" word is reserved. The only thing, i'm thinking about - will it cross-database or not...
AntonAL