has_many :through

Mat Ellis mat at tecnh.com
Fri Feb 11 15:39:09 EST 2011


We're still thoroughly in an ActiveRecord mindset over here. Before we go and build some simple collect statements to replace a few has_many :through statements, is there some Ripple or Riak goodness we should be using instead?

Example:

* A Publisher has many Authors who have many Books
* We want to get a set of books for a given publisher
* In ActiveRecord we would say:

# publisher.rb
class Publisher < ActiveRecord::Base
  has_many :authors
  has_many :books, :through => authors
end

# author.rb
class Author < ActiveRecord::Base
  belongs_to :publisher
  has_many :books
end

# book.rb
class Book < ActiveRecord::Base
  belongs_to :author
end

Thanks

M.





More information about the riak-users mailing list