Skip to content

Instantly share code, notes, and snippets.

@eltiare
Created August 17, 2009 22:47
Show Gist options
  • Select an option

  • Save eltiare/169425 to your computer and use it in GitHub Desktop.

Select an option

Save eltiare/169425 to your computer and use it in GitHub Desktop.
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