I am trying to bring back related data (i.e. combine two tables), much like numerous topics already on the forum. I have been through them all and cannot see how to get it working in codeless. I have so many questions but am going to start with a basic one because I am falling at the first hurdle…
Two tables; ‘User’ and ‘UserWorkouts’. Want to bring in values from the ‘User’ table for fields such as country and city in to the ‘UserWorkouts’ table…so all 1:1 relations and both tables have ownerId (and objectId).
This is my ‘UserWorkouts’ table;
What I don’t understand is how to dynamically link/relate them. Going through manually and linking each new record in ‘UserWorkouts’ is…crazy
I have created the basic codeless below which is working for entries where I manually populate but I get null for the others;
I have spent a few days on this (not complaining!!!) and I just cannot crack it…
Definitely )), so you should do it programmatically please check out an example here Transaction API - Backendless Codeless Development Guide
This is getting too complex for me.
This was a ‘nice to have’ for me…already too much time spent on it, so I have to give up.
I have found Backendless great to work with, but I have to say, ‘joining’ two tables has simply overwhelmed me…
A relationship between two objects start with a relationship declared in the tables where those objects reside. You have two tables:
UserWorkouts. Have you created a relationship column in the
User table? I’d imagine it would be a
1:N relation since a user may have zero or more workouts.
Once a relationship column is created, you can relate workouts to users. How does it work? There is a block in codeless that let’s you take a workout object (or multiple objects) and relate them to a user. Suppose the name of the relation column is
userWorkouts, then creating a relation between a user and their workout would be as simple as this:
Why am I sharing this information when you asked for retrieving related data? Well, in order to retrieve related data, you should have related data first and what I described above is how you get to that point.
Hope this helps.
Appreciate the response, but isn’t this what I did earlier?
I created a 1:1 relation in the table = UserWorkouts with table = Users, and I called that column in UserWorkouts ‘user’. It is one-to-one because each workout only has one User, and I have the identification column as ownerId.
Or are you saying I need to set the relation up in both tables?
When I invoke what I have, it works for objects in table = UserWorkouts where I have manually clicked the relation. Is the above the automation of that clicking?
When you create a column in a table you establish a “skeleton” for the data. When you store objects in the table, do you create a relationship between the objects that follows that “skeleton”. That’s the part I didn’t see from your posts. To put things in perspective:
- You have a relationship column declared in the
- Objects in the
UserWorkouts table need to have data for that relationship column. What this means is that a specific user workout needs to be related to a specific user object. To make it happen you need to establish the relationship between the objects using the codeless block I pointed.
I dont know where I get the objects (userObject and workoutObject) to add them…
Why did you create these tables then? Doesn’t your application use these tables?
Yep, I use them and they work great. What I mean is, I dont know how to create these blocks below…to insert them in. I really am out of my depth here.
Is there a place in your app when a new workout is created?
I am using AppGyver as front end. A user saves a workout and an API POSTs the data to the UserWorkouts table…
When the user saves a workout, you need to make another API call to link the workout with the user. “Linking” here is exactly the process of establishing a relationship in the database. The API call is documented here:
I didn’t know you are using AppGyver, that’s why I originally suggested the codeless block. When you build with Backendless UI Builder, things get much simpler, but with AppGyver, there is an API call I mentioned that you need to set up.
Brilliant, I have that working now. Incredible! I have one more big question but that is for tomorrow…
Thanks for your help.
Great! Please help me understand what was the a-ha moment? Where were you looking for information and couldn’t find it? I am just trying to figure out how to make it more obvious and easier for developers to implement on their own.
I think this topic was difficult in that what I needed to do was slightly unique because I am using AppGyver and not backendless.com for both my front end and back end.
On this particular topic, it was a bit of an effort finding out how to ‘join’ the tables…like other people, I have SQL knowledge so was coming at it from that angle. But after reading through almost every topic and watching the relevant video, I figured I had ‘built the skeleton’ correctly and could manually relate the objects. But it terms of doing that dynamically, the trail went cold…and I was completely confused. And I kept going over the topics and videos to see what I was missing but conceptually couldn’t figure it out.
For me, someone with no coding experience (I didn’t know what an API was when I started), documentation is the key. With Backendless, a few key documents such as setting up authentication (with Appgyver front end) and the one re building a service to eliminate 100 record pagination…these were key for me. They are the reason I went with Backendless, because they spoonfed me, as I don’t have the skills to be able to do that unassisted, not quickly anyway, so I need to follow a process/example…need to be walked through it. And I would say generally, you have lots of good documentation but you could never have too much of that. Particularly with codeless, basic examples of what each block does and how they interact would help, but maybe they exist? I guess all I am saying is that example code helps…not particularly enlightening…
Hope this helps. Genuinely though, I am a complete novice at all this, and I have been able to get pretty far with backendless. Everything so far I have wanted to build, I have managed it.