Can you perform a Query on a Table that exists but has no Mode in Rails?
Rails auto-generated a join table in this relationship :
# User.rb
has_and_belongs_to :topics
# Topic.rb
has_and_belongs_to :u开发者_开发百科sers
I want to query the join table, topics_users
directly for a to obtain an ID's.
This strategy I feel would be the fastest at getting the User ID's from the Topics, rather than looking up the Join Table, looking up the Users, and Getting the ID's from the users.
If you really want to you can execute manual sql queries as follows:
ActiveRecord::Base.connection.execute("SELECT id FROM users_topics WHERE etc")
精彩评论