0

I am having trouble returning all profiles that have blocked you with the amistad gem.

I am able to find profiles you have blocked.

And the profiles other individual profiles have blocked.

a = Profile.find_by_id 6
b = Profile.find_by_id 7

b.block_profile a

a.blockades

  Profile Load (0.2ms)  SELECT ".."

 => #<ActiveRecord::Associations::CollectionProxy [#<Profile id: 18....>]>

a.blockades_by

  Profile Load (0.2ms)  SELECT "profiles".* FROM "profiles" INNER JOIN "friendships" ON "profiles"."id" = "friendships"."friendable_id" WHERE "friendships"."blocker_id" = ? AND (friendable_id <> blocker_id)  [["blocker_id", 6]]
 => #<ActiveRecord::Associations::CollectionProxy []>

 b.blockades
  Profile Load (0.2ms)  SELECT "...."
 => #<ActiveRecord::Associations::CollectionProxy [#<Profile id: 6,....>]>
Oky, so it works if you know which profile exactly to look at.

But the issue is I would need to iterate through every profile and look at their blockades_by to see if the logged in user is there, then remove them from the final query. This is way too crazy. There needs to be a simpler way?

bezzoon
  • 1,755
  • 4
  • 24
  • 52
  • Is this the [amistad gem](https://github.com/raw1z/amistad) you're using? If so I'm a bit confused, I don't see a `blockades` or `blockades_by`, maybe I'm just missing something in their documentation. What's the difference esteem those two methods? – Paul Richter May 08 '14 at 23:48
  • it isn't in the documentation, one is the id of the person you blocked and one is your id. I think the solution is to iterate through all Profiles and if they blocked at that to a list? – bezzoon May 08 '14 at 23:54

0 Answers0