开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜