I am using Laravel migrations to create/manage all of my database scripts and I have a migration for creating a trigger.
Here it is
DB::unprepared(
'create trigger update_points_aft_insert
after insert on votes
for each row
begin
declare u_id integer;
if NEW.votable_type = "App\\Comment" then
set u_id = (select user_id from comments where id = NEW.votable_id);
update users set points=points+NEW.vote where id = u_id;
end if;
end;'
);
The problem is when I run show triggers; I get:
*************************** 1. row ***************************
Trigger: update_points_aft_insert
Event: INSERT
Table: votes
Statement: begin
declare u_id integer;
if NEW.votable_type = "AppComment" then
set u_id = (select user_id from comments where id = NEW.votable_id);
update users set points=points+NEW.vote where id = u_id;
end if;
end
Timing: AFTER
Created: NULL
sql_mode: NO_ENGINE_SUBSTITUTION
Definer: root@localhost
character_set_client: utf8 collation_connection: utf8_unicode_ci Database Collation: latin1_swedish_ci
As you can see, what mysql read is if NEW.votable_type = "AppComment" then instead of what I want: if NEW.votable_type = "App\Comment" then ... Anyone know how I can tell mysql to read the backslash?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire