I am using Dr.Nic Composite Primary Keys for rails (http://compositekeys.rubyforge.org/)
In the examples, it has has_many and belongs to a relation, but not has_and_belongs_to_many
My association works well with books in genres (books contain complex title and author body text), but the genre in books tries to query for the column book_id, which is not in the connection table, and causes an error.
class Book < ActiveRecord::Base self.primary_keys = :title, :author has_and_belongs_to_many :genres, foreign_key: [:title, :author] end class Genre < ActiveRecord::Base has_and_belongs_to_many :books, foreign_key: [:title, :author] end
Edit: I also got it to work using the :association_foreign_key option in the Genre model
class Genre < ActiveRecord::Base has_and_belongs_to_many :books, association_foreign_key: [:title, :author] end
ruby-on-rails
Vall3y
source share