hakarabakara1

hakarabakara1

Getting tsvectors: error] ** (Postgrex.Error) ERROR 42703 (undefined_column) record “new” has no field “business_id”

I have three modules, a Business which is associated Tags and Categories though join tables business_tags and business_categories. I intent to improve search hits on the business using tsvector on the database and I have a column searchable on the business which initially was built from the business’ name and description. I want to extend this to the tags and categories such that when tags and categories are assigned to the categories, these would be integrated into the searchable column.

Here’s my migration

execute("""

      CREATE OR REPLACE FUNCTION public.businesses_searchable_trigger()
       RETURNS trigger
       LANGUAGE plpgsql
      AS $function$ begin
      update
    businesses b
      set
    searchable = setweight(to_tsvector('pg_catalog.english', coalesce(b.name, '')), 'A') || setweight(to_tsvector('pg_catalog.english', coalesce(b.description, '')), 'D') || setweight(to_tsvector('pg_catalog.english', coalesce(( select string_agg(distinct t.name, ' ') from business_tags bt join tags t on t.id = bt.tag_id where bt.business_id = b.id ), '') ), 'C') || setweight(to_tsvector('pg_catalog.english', coalesce(( select string_agg(distinct c.name, ' ') from business_categories bc join categories c on c.id = bc.category_id where bc.business_id = b.id ), '') ), 'C')
      where
    b.id = coalesce(NEW.business_id, OLD.business_id);

      return coalesce(new, old);
      end;

      $function$
      ;
    """)

    # Triggers on join tables
    execute("""
    CREATE OR REPLACE TRIGGER business_tags_rebuild_searchable_trigger AFTER INSERT OR UPDATE OR DELETE ON business_tags FOR EACH ROW EXECUTE FUNCTION businesses_searchable_trigger();
    """)

    execute("""
    CREATE OR REPLACE TRIGGER business_categories_rebuild_search_trigger
    AFTER INSERT OR UPDATE OR DELETE ON business_categories
    FOR EACH ROW
      EXECUTE PROCEDURE businesses_searchable_trigger();
    """)

When I attempt to insert a business, it breaks with the following error message:

error] ** (Postgrex.Error) ERROR 42703 (undefined_column) record “new” has no field “business_id”

I will appreciate any form of guidance

First Post!

christhekeele

christhekeele

This is coming from this line in your first update businesses trigger:

b.id = coalesce(NEW.business_id, OLD.business_id)

I would guess that businesses.business_id does not exist.

Where Next?

Popular in Troubleshooting Top

ChrisAmelia
Currently reading and experimenting through, which is in 1.6 Chapter 7: Sign up | Phoenix Tutorial (Phoenix 1.6) | Softcover.io In regar...
New
hakarabakara1
I have three modules, a Business which is associated Tags and Categories though join tables business_tags and business_categories. I inte...
New
rathoud96
Environment Elixir 1.18.3-otp-27 / OTP 27.3.4 Oban 2.20.2 Phoenix 1.7.x db_connection 2.8.1 / Postgrex 0.21.1 Infrastructure: Google Cl...
New
hyperoceanic
Having read the book, I’m keen to explore Ash a bit more, but I’m falling at the first hurdle - the creation of a new project. Here’s my...
New
ktayah
Environment Oban Pro: 1.7.6 Oban: 2.22.1 Issue When a sub-workflow built with Workflow.put_context/2 is attached to a parent via ...
New
Lotoen
Hello, I am currently using Elixir 1.18.4 and OTP 27 with Linux Mint 22.3 - Cinnamon 64-bit as my operating system. I came across this er...
New
tellemiller
We recently started running Oban with Oban Web on PostgreSQL (AWS RDS gp3) and noticed our oban_jobs buffer cache hit ratio sitting at 65...
New
anotherpit
A graft inside another graft causes Oban.Pro.Workflow.status to recurse forever. oban_pro 1.7.5 defmodule App.NestedGraftRepro.Test do ...
New
bugnano
Hello everyone. I’m the author of GitHub - bugnano/wtransport-elixir: Elixir bindings for the WTransport WebTransport library · GitHub ,...
New
ndan
Oban.Pro.Migration.up(version: "1.7.0", only: :indexes) fails on partitioned oban_jobs table when upgrading Oban Pro from 1.6 to 1.7 def...
New

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New

We're in Beta

About us Mission Statement