17 lines
447 B
SQL
17 lines
447 B
SQL
DROP FUNCTION IF EXISTS mocha_get_instance_by_key;
|
|
|
|
CREATE FUNCTION mocha_get_instance_by_key
|
|
(
|
|
p_class_id INT,
|
|
p_inst_id INT
|
|
)
|
|
RETURNS INT
|
|
RETURN (SELECT id FROM mocha_instances
|
|
|
|
WHERE (tenant_id = mocha_get_current_tenant()
|
|
OR tenant_id IN (SELECT target_tenant_id FROM mocha_tenant_references WHERE source_tenant_id = mocha_get_current_tenant())
|
|
)
|
|
AND class_id = p_class_id
|
|
AND inst_id = p_inst_id
|
|
LIMIT 1
|
|
); |