Home>

I want to retrieve the record of the parent model associated with the record that has a specific value of the child model
I want to display members whose status is not supported

ActiveRecord :: StatementInvalid in Tops # index

Mysql2 :: Error: Unknown column'member_status.status' in'where clause': SELECT `members`. * FROM` members` INNER JOIN `member_statuses` ON` member_statuses` .`member_id` = `members`.` id` WHERE `member_status`.` status` ='Unsupported'
Corresponding source code
tops_controller.rb
class TopsController</pre>
<pre><code data-language = "Ruby">member.rb
class Member</pre>
<pre><code data-language = "Ruby">member_status.rb
class MemberStatus</pre>
<pre><code data-language = "Ruby">20XXXXX_create_member_statuses.rb
class CreateMemberStatuses</pre>
<pre><code data-language = "Haml">[email protected] members_unsupported.each do | member |
% tr.details-new
 --member ....
What I tried

The above description causes an error, so I tried include and eager_load, but it didn't work.

Supplementary information (FW/tool version, etc.)

rails 5.2.4
ruby 2.5.1

Since this is my first question, I think there are some omissions.
Please let us know if you have the information you need! !!
Thanks for your cooperation.

  • Answer # 1

    ON member_statuses.member_id = members.id WHERE member_status.status
    The table name in the ON clause is plural, but the WHERE clause is in the singular.
    where (member_statuses: {status:'not supported'})To.
    I think Rails should do his best too. .. ..
    Maybe.where ("member_statuses.status =?",'Unsupported'}It may be useless if you do not.