That doesn't quite accomplish what I'm trying to do. BookReader.first.books.all(:order => [:published.desc])
gives me Books; what I'm after are Checkouts, sorted by Book's :published column On Monday, September 3, 2012 12:54:31 AM UTC-7, armanx wrote: > > I'm looking to sort records in one table, based on a date column in > another table. For example, I have the following tables: > > class BookReader >> include DataMapper::Resource >> has n, :checkouts >> has n, :books, :through => :checkouts >> property :id, Serial >> property :name, String >> property :city, String >> end >> class Book >> include DataMapper::Resource >> has n, :checkouts >> has n, :readers, :through => :checkouts >> property :id, Serial >> property :title, String >> property :author, String >> property :published, Date >> end >> class Checkout >> include DataMapper::Resource >> belongs_to :bookreader, :key => true >> belongs_to :book, :key => true >> property :created_at, DateTime >> property :updated_at, DateTime >> end > > > (This assumes each BookReader can only check out each Book once). > I can select all the Book objects belonging to a particular BookReader: > > checkouts = BookReader.first.checkouts > > > Now, I want to sort these based on the :published date of the Book object. > E.g.: > > SELECT >> c.*, b.date >> FROM >> "checkouts" as c >> JOIN "books" as b on b.id = c.book_id >> WHERE >> c.bookreader_id = 1 >> ORDER BY >> b.date DESC > > > Any way to do this directly through DM? > -- You received this message because you are subscribed to the Google Groups "DataMapper" group. To view this discussion on the web visit https://groups.google.com/d/msg/datamapper/-/Nayx-lp5oksJ. To post to this group, send email to datamapper@googlegroups.com. To unsubscribe from this group, send email to datamapper+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.