This project is archived and is in readonly mode.

#1252 ✓resolved
Tom Lea

Bad self referential HABTM associations should fail fast.

Reported by Tom Lea | October 22nd, 2008 @ 11:36 PM | in 2.x

Self referential HABTM associations should not be allowed to be created unless the association_foreign_key has been manually assigned.

If this is not prevented, we end up with an join table which has only one column, which is referenced twice... causing odd and confusing results (which caused me a headache!).

This patch causes trying to do this to fail fast, saving on debug time.

Rough Example:


class Person < AR::Base
	habtm :friends, :join_table => :person_friend_pairings
end

alice = Person.create! :name => "Alice"  # id => 1
bob = Person.create! :name => "Bob"		 # id => 2
alice.friends << bob

alice.reload
alice.friends.to_a # SELECT * FROM person_friend_pairings where person_id = 2

Tagged as an enhancement, but could be a bug... feel free to change it.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Referenced by

Pages