Übereinstimmende Array-Werte in PostgreSQL mit ActiveRecord
In meiner Rails 4 App habe ich mir zum Ziel gesetzt, alle Kontakte zu sehen, wo Feldvisible_to
in der Kontakttabelle gleich 1. Myvisible_to
ist:integer, array: true
.
Ich erhalte jedoch die folgende Ausnahme:
PG::UndefinedFunction: ERROR: operator does not exist: integer[] = integer LINE 1: ....* FROM "contacts" WHERE "contacts"."visible_to" IN (1) OR... ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.: SELECT "contacts".* FROM "contacts" WHERE "contacts"."visible_to" IN (1) ORDER BY created_at DESC
Ich habe nach Antworten gesucht und es gibt meines Erachtens ein Problem mit einer Art vonvisible_to
. Ich konnte jedoch keine Lösung finden. Ich habe auch versucht, von Cast-Hinweisen zu profitieren, aber vergebens.
Meine Migration:
class AddVisibleToToContacts < ActiveRecord::Migration
def change
add_column :contacts, :visible_to, :integer, array: true, default: [], using: 'gin'
end
end
Relevante Variable vom Controller:
@contacts_all_user_sorted = Contact.all.where(visible_to: [1]).order("created_at DESC")