[LRUG] Scoping sequences to a parent
Andrew Stewart
boss at airbladesoftware.com
Fri Sep 2 04:43:44 PDT 2016
> How do you feel about database triggers?
Mixed ;)
> Something like this should do what you're after, I think:
>
> ```
> CREATE TRIGGER ensure_children_are_indexed_scoped_to_parent
> AFTER INSERT ON child_table
> UPDATE child_table SET index = MAX(index) + 1 WHERE id = LAST_INSERT_ID();
> ```
>
> No idea if it still works, but you could manage them using something like `hair_trigger`:
>
> https://github.com/jenseng/hair_trigger <https://github.com/jenseng/hair_trigger>
Thanks for the suggestion. I hadn't considerd triggers at all...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20160902/3dc72dfd/attachment-0002.html>
More information about the Chat
mailing list