Avoid db._get_by_extkey in cast

Not that I love this new version, but it's a bit more robust.
The trigger knows the table and the function it depends on