I know there are a few ways to join / include tables, but here I want to get data from 2 tables By using ActiveRecord.find_by_sql.
example) have 2 tables.
Table 1: User {id: integer name: string} Table 2: UserComment {id: Integer user_id: integer comment: string} What is the need to recover ActiveRecord
select u.names, count (UK comment) user u, userm uc in U.ID = UK.USRIID group U.Name How can we write it with activation code? Return only to the U. N. name below: Select Is there a possible way of using the base.connection.Secute to the SEC? Umm, but it does not look the best .
sql = 'Select UEAM, User U, User Comment from UED = UK.USURIID Group U.Name' Acti If you have a , then you have a .base.cnation.exeqsq < Is_many: user_comments defined in your user model:
User.joins (: user_comments) .group (: name) .count
No comments:
Post a Comment