-
-
Save wflanagan/95f06f29fcf7d57e807548b03ed07483 to your computer and use it in GitHub Desktop.
Problem with postgresql array. when i do this query for references, it errors with a SQL statement invalid. Rails 5.2.x and Ruby 2.6.4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.describe "Profile Clusterable" do | |
let(:json_profiles) { FileManager.json_read_from_fixture_path("clustering/feature_writer_profiles.json") } | |
let(:profiles) do | |
profiles = [] | |
skip_fields = %w[custom_field id similarity source source_types status type work depth interests longitude latitude service service_id] | |
json_profiles.each do |json_profile| | |
json_profile["friendly_id"] = json_profile["id"] | |
json_profile["kind"] = json_profile["type"] | |
json_profile["lat"] = json_profile["latitude"] | |
json_profile["lng"] = json_profile["longitude"] | |
profile = Profile.new(json_profile.except(*skip_fields)) | |
profile.enriched_at = Time.now | |
expect(profile.save).to be_truthy | |
profiles << profile | |
end | |
profiles | |
end | |
it "works" do | |
profiles | |
profile = Profile.first | |
resp = profile.referencing_profiles | |
expect(resp.map{|record|record.references}.flatten).to include profile.friendly_id | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ProfileClusterable | |
extend ActiveSupport::Concern | |
def referencing_profiles | |
# Profile.find_by_sql("SELECT * FROM profiles WHERE references && '{#{friendly_id}}'::text[];") | |
Profile.where("'#{friendly_id}' = ANY (references)") | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create_table "profiles", force: :cascade do |t| | |
t.integer "parent_id" | |
t.string "friendly_id" | |
t.string "kind" | |
t.string "identifier" | |
t.string "username" | |
t.string "user_id" | |
t.string "url" | |
t.string "name" | |
t.string "first_name" | |
t.string "middle_name" | |
t.string "last_name" | |
t.text "description" | |
t.string "gender" | |
t.string "image_url" | |
t.string "job_title" | |
t.string "job_company" | |
t.string "education" | |
t.string "location" | |
t.string "country" | |
t.string "territory" | |
t.string "city" | |
t.string "address" | |
t.float "lng" | |
t.float "lat" | |
t.string "lang" | |
t.string "ad_networks", default: [], array: true | |
t.string "tags", default: [], array: true | |
t.integer "followers" | |
t.integer "following" | |
t.integer "listed" | |
t.integer "liked" | |
t.integer "shares" | |
t.string "rss" | |
t.integer "enrichment_attempts", default: 0 | |
t.integer "image_url_simhash" | |
t.datetime "enriched_at" | |
t.datetime "enrichment_last_attempted_at" | |
t.datetime "created_at", null: false | |
t.datetime "updated_at", null: false | |
t.jsonb "data", default: {} | |
t.jsonb "custom_fields", default: {} | |
t.string "domain" | |
t.jsonb "matcher", default: {}, null: false | |
t.text "references", default: [], array: true | |
t.index ["identifier", "username", "user_id"], name: "index_profiles_on_identifier_and_username_and_user_id", unique: true | |
t.index ["matcher"], name: "index_profiles_on_matcher", using: :gin | |
t.index ["references"], name: "index_profiles_on_references", using: :gin | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment