-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unable to create trigger with custom name #22
Comments
@mothra I wonder if the issue is because you are using a trigger group? The name is set on the outer group, not on the inner trigger definition. When generating the actual trigger SQL, that name would only be used in MySQL, since it creates a single trigger for the whole group. PostgreSQL (and SQLite) will have a separate trigger for each definition within the group, thus it will infer names for them (unless they have explicit ones set). So either of these approaches may be helpful:
trigger.after(:update).name('contacts_trigger_custom_name').where("OLD.foo != NEW.foo") do
"Bar"
end
trigger.after(:update) do |t|
t.name('contacts_trigger_custom_name').where("OLD.foo != NEW.foo") do
"Bar"
end
end |
Thanks, @jenseng. I ended up using your first option. I had originally tried using a trigger group as in your second option, but got the following error:
|
Interesting, I'll see about fixing that error. Also we can leave this ticket open... Aa a minimum the docs should be updated so the behavior is more clear. Maybe hairtrigger could also issue a warning if the group has an explicit name but the triggers in it do not. |
Terrific, thanks! |
Hello,
I am unable to use the 'name' option to create a trigger with a custom name. Here is an example of the trigger in my model:
The auto-generated migration looks like this:
When I run that migration, the trigger has the name
contacts_after_update_row_when_old_foo_new_foo_tr
instead of my custom name. I am trying to create several update triggers with similar conditions, and the result is that only one trigger is created with the auto-generated name. So far my workaround has been to add bogus conditions to the triggers so that they are created with different names:I am using Rails 3.2.13, hairtrigger 0.2.4, pg 0.17.0, and PostgreSQL 9.2.
Thanks.
The text was updated successfully, but these errors were encountered: