开发者

Can you perform a Query on a Table that exists but has no Mode in Rails?

开发者 https://www.devze.com 2023-02-22 10:42 出处:网络
Rails auto-generated a join table in this relationship : # User.rb has_and_belongs_to :topics # Topic.rb

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")
0

精彩评论

暂无评论...
验证码 换一张
取 消