title: Select the correct record in an <ActiveRecord::Associations::CollectionProxy>
body: <p>I'm trying to understand what I'm doing wrong here - if someone can point me in the right direction, that would be great!</p>
  <p>I have the following associations in my application:</p>
  <pre><code>class Notification &lt; ApplicationRecord
      belongs_to :notificationable, polymorphic: true
  end
  
  
  class AccessPermission &lt; ApplicationRecord
      belongs_to :project
      has_many :notifications, as: :notificationable, dependent: :destroy
  end
  
  </code></pre>
  <p>In one of my controllers, I have a call that finds all Access Permissions that belong to a project, and then select all the notifications for that collection of Access Permissions. But I'm having a bit of trouble. I thought a call like <code>AccessPermission.where(project_id: 1).notifications</code> would work, but it doesn't. So I resorted to doing this in ruby using <code>.map</code></p>
  <pre><code>
  if AccessPermission.where(project_id: 1).map(&amp;:notifications).include?(Notification.where(recipient_id: 1))
              
      #Here is where I need help. Find the notification record in the ActiveRecord::Associations that made the call above &quot;True.&quot; I tried:
       notification = AccessPermission.where(project_id: 1).map(&amp;:notifications).find(Notification.where(recipient_id: 1)).first
  
      ## That did not work, it returns an enumerator and then selects the very first object of the array no matter what the recipient_id is
  
  else
              
      #create the notification if no notification exists
      access_permission.create_notification(recipient_id: 1)
  end
  
  </code></pre>