Relationship issue

Hello, i’m looking for some help setting relationships between tables. I have a sql background, and am attempting to structure the tables in typical sql fashion with an ID column that links to another table with a corresponding ID. For example, the main table would have a [StockID] column, that has a relationship to CompanySectors table column [StockID]. CompanySectors has a column [SectorID] that has a relationship to MiningSectors column [SectorID].

Looking at documentation/youtube videos, it looks like i cannot declare a relationship between columns that already exist. If i delete my columns like [stockID] and add a new column with relationship to another table, the column is blank and i have to add the relationship for each record one by one??

Any help would be appreciated, just keep in mind that i am not a coder and barely have figured out using an API :slight_smile:

Hi Joel,

Welcome to the Backendless community.

In Backendless, a relationship is established between tables by creating a relationship column. There is a special column type that specifically represents a relationship. For instance, say you have two tables: Person and Address and a single person can have multiple addresses, then you can create the addresses column in the Person table that would have the “one-to-many” cardinality:

From the code representation perspective, the Person class will have a collection field/property named addresses that will have the collection of the related Address objects.

A relationship column can be created either in Backendless console or using the API, here’s REST version:
https://backendless.com/docs/rest/data_set_add_relation_rest.html

Hope this helps.

Regards,
Mark

Thanks Mark, I think that helps me understand how Backendless handles relationships. Once the relationship columns are created do i manually set the relationship between records?

You are welcome. Relationship between objects can be done either in the Backendless console or using the API. If you are interested in the latter, please let me know which SDK you’d be using (Android, iOS, JS, flutter, .net).

Regards,
Mark

I’d like to accomplish it in the console if possible, I’m not too familiar with using the api other than simple GET commands on my data. The end product will be a web app, with the UI built in backendless or UI Bakery.

Hello @Joey_Hillam

You can of course do this in the console. Perhaps this article will be useful to you when working with tables in Backendless.

Regards,
Inna

@Inna_Shkolnaya Thanks Inna. I believe i have the relationships set for two of my tables. Now i am having trouble querying that related data in my UI data table:
Schema

WHERE clause:
image

No results, should be 12. I believe i have the syntax correct based on the video “Database Integration - Querying the Database”.

Try the following whereClause:
MiningSectors[Stock].SectorID=2

Yes!! Exactly what i expected to return, thank you so much. Just to make sure i have the syntax: Relatedtable[relationshipColumn].column <-column to apply the operator to.

To generalize the definition of the syntax, it is:

ParentTable[ relationColumnInTheParentTable ].ColumnNameInTheParentTable