I have a Ruby on Rails application in which the code directly access many-to-many join tables directly. This makes modifying some of the code very difficult since it bypasses the normal associations and methods created via the :has_many and :has_many :through relationships.
My question is simply, is this an acceptable thing to be doing or should this be avoided?
In my mind, from the database point of view, the join tables do not exist in the logical view. As such, there should be no reason to ever access them directly. One should simply ignore that they even exist and let the framework take care of them.
What do others think?
To be more precise, I am wondering if the following should ever appear in code:
Person { name }
Group { name }
PersonGroup { person_id, group_id, membership_state }
PersonGroup.find(:all, :conditions => {:membership_state => 'pending'} }
I am thinking that instead of using the join table, one should instead scope the request to the Group and find all pending members that way.