简体   繁体   中英

Rails Not In - Amistad Gem - Not selecting people that have blocked you or you have blocked

Using the amistad gem I can get People.all

After reviewing the documentation it looks like

People.blockades and People.blockades_by

returns the people that have blocked you and the people you have blocked

https://github.com/raw1z/amistad/wiki

Is it possible to return a query of all the people except those you have blocked and those that have blocked you? i have spent a lot of time trying to figure this out to no avail. Where you are a, and

a = People.first # or any person, really

With normal SQL one could do a not in query but I can't figure this out with rails.

What I tried

People.where(:condition => "id NOT IN #{ids.join(',')}")

ERROR

: SELECT "peoples".* FROM "peoples"  WHERE "peoples"."condition" = 'id NOT IN 11,106'
PG::UndefinedColumn: ERROR:  column peoples.condition does not exist
LINE 1: SELECT "peopless".* FROM "peopless"  WHERE "peoples"."condi...

For you query you would need something like:

People.where('id NOT IN (?)', ids)

where ids is an array of id numbers (eg [11,106] )

Now, I don't know amistad , but you might want to try doing a simple subtraction to get your require list of people. Something like:

People.all - People.blockades - People.blockades_by

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM