Related object properties in Generated column

Hi team,

Great work with the generated columns feature. I’d like to know if it’s possible to use properties from a related table in a generated column expression. I’m implementing a notification system, where the Notifications table has the “contentTemplate (string)” and “actor (User)” columns, among others. Is it feasible to define a generated column (name it “displayText”) for replacing a text within “contentTemplate” with the actor’s name?

For instance:
contentTemplate: “{{actor_name}} posted a comment in your photo.”
actor: Points to a record of Users. { name: “John Doe”, email: … }
displayText expression: REPLACE(contentTemplate, “{{actor_name}}”, actor.name)
displayText: “John Doe posted a comment in your photo.”

How can I accomplish that? So far, I’ve only been able to reach User’s objectId and ownerId.

1 Like

Hi Rafael!

Unfortunately only columns from table, to which generated column is added, can be used in generated column expressions. If you want to generate value basing on columns from other tables, you must do it in your code.

Regards, Andriy

1 Like

Or if you are using Backendless Push notifications, you can do it without the use of generated columns. This is what “Smart Text” is for in our push notifications templates.

Hello @RAFAEL_PEREZ,

I’d like to know if it’s possible to use properties from a related table in a generated column expression

No, it is not possible, because of MySQL limitation https://dev.mysql.com/doc/refman/5.7/en/create-table-generated-columns.html

Subqueries are not permitted.

So it is not possible for us to support relations in generated columns.

2 Likes

Got it. Thanks!

Hi!
Thanks, I find Smart Text really useful but the notifications I’m talking about are not actually push notifications but just notifications that will be persistent within the app.