Created
August 17, 2009 22:47
-
-
Save eltiare/169425 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SuperParent | |
| include DataMapper::Resource | |
| property :id, Serial | |
| has n, :parents | |
| end | |
| class Parent | |
| include DataMapper::Resource | |
| property :id, Serial | |
| property :super_parent_id, Integer, :index => true | |
| property :ord, Integer, :index => true | |
| has n, :children | |
| belongs_to :super_parent | |
| default_scope(:default).update(:order => [:ord.asc]) | |
| end | |
| class Child | |
| include DataMapper::Resource | |
| property :id, Serial | |
| property :parent_id, Integer, :index => true | |
| belongs_to :parent | |
| # GOT IT! This is what makes it work: | |
| default_scope(:default).update(:order => [DataMapper::Query::Direction.new(Parent.properties[:ord])], :links => [:parent]) | |
| # Got info from: http://www.mail-archive.com/datamapper@googlegroups.com/msg01310.html | |
| end | |
| # I want to be able to do this, and have it order by the ord attribute on the `parents` table | |
| super_parent_instance.parents.children |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment