Special case of relations

Hi everyone,

My first page is showing my categories. Due to my design, and also to provide a very fast service, I can’t make a find() request to Backendless to get my categories and, eventually, use the AutoLoad to get all the companies related to the category selected. I really want to keep that first screen always ready.

So my idea was to keep storing my categories in Backendless, keep using the relations in Backendless, and for example, when I click on Restaurants, I pass the Backendless’ objectId of the category Restaurants via a segue, and do a request with a kind of whereClause with it.

The point is I don’t know how (or if it is possible), to use the category key in the Companies table (in my screenshot the column Category.companies)
/Users/vincentdurmort/Desktop/relationExample.jpg</img>

The common sense be to add a property named “Category.companies” to my Company class… but that impossible.

Any help, or a completely different idea would be appreciated, as usual.
Reward : my gratitude and a beer, on me, if you dare to travel to China to meet me :smiley:

Thanks a lot !

relationExample.jpg

Could you please re-attach the screenshot? It does not open for some reason.

Also, please describe how you defined your relationship? By that I mean in what table did you add a relationship column and what other table it points to.

Thanks,
Mark

I created my relationship in the Category table (one to many) linked to Company table based on a video you sent in another topic. Which means I have a column named Category.companies in the table Company…

Wait a minute, before watching your video my first call was to declare my relationship as OneToOne in the Company table instead of a OneToMany in the Category Table… In my case it could do the job no?

For sure if I want to use the autoload and get all the companies related to a category I should declare my relationship as OneToMany in the Category table right?

the file again

relationExample.jpg

Do your file attachments open for you? Because they are not working for me.

Now, on to your message: if you created a relationship (column) in the Category table, it will exist in the Category table. The table the relationship points to (Company in this case) does not get any columns. What you see in the console is simply a visualization showing parent data objects:
http://support.backendless.com/public/attachments/3d4e71005be3c8e73334f6bda8c9728a.png&lt;/img&gt;

Columns defined in a table can be seen in the table schema, which is a screen you get to when you click the “Table Schema and Permissions” red button in the upper right corner of the interface.

As for your original question, to load all companies for a category, you can use the “loadRelations” method. Here’s an article with an example showing how to use it:

Yes my screenshots work from here. Strange. Sorry about that.
Thanks for the explaination about the child visualization.

I am not sure if I explained clearly enough the situation, but could you tell me if it is a good way to set a OneToOne relationship in the table Company instead of a OneToMany in the table Category?

Thanks

One to one defined in Company and pointing to Category, is almost equivalent of one to many defined in Category and pointing to Company. The reason I say “almost” is because the 1:1 relationship from Company to Category would not let you place a company in more than one category. However, if you go with 1:N from Category to Company, you will not have that limitation.

That’s perfect. A company can belong to only one category. Furthermore I’ll be able to get the category objectId from the company table and filter my companies by their category objectId.

Thanks!