Support Topics Documentation Slack YouTube Blog

Use Relations Count in Load Data block in Codeless

I am trying to use the Load Table block in Codeless to retrieve objects that have fewer than 2 relations.

Eg.

Parent table, parent A has 3 student relations in the student table
Parent table, parent B has 1 student relation in the student table

I want to search the parent table and find only parent B.

What search syntax should I use?

Hi @Andreas_Marinopoulos ,

assuming you have following tables structure

here is an example of how to achieve the behaviour you would like to have:

Hope this helps!

Regards,
Stanislaw

This is exactly what I need @stanislaw.grin !

But I’m doing sth wrong, or is it normal I can’t get it to work in the data browser? I am in the parents table, doing:

image

but I get an error.

Hello @Andreas_Marinopoulos

Please describe in more detail what you are doing, since from the screenshots I do not quite understand under what circumstances the error occurs.
What error are you getting?

Sure, please excuse the brevity.

I have two tables as above, with a 1:N relation between them.

My goal is to search in the parent table for parent objects that have over 2 relations with objects in the child table.

I am going to the Backendless UI, in the Data section and performing a search in the search bar.

What do you mean by

Backendless UI, in the Data section

= Console - Data - ParentTableName - DATA BROWSER?

1 Like

Hi Andreas, you would not be able to perform that search in the Data Browser as it requires grouping with a “having” condition. However, you can either use REST Console, or you can create a view that will automatically pull the required data. Here’s a 4 part series describing how to work with views:

Regards,
Mark

Thanks both, I’ve already watched the videos and am using views a lot, thanks!

Hi @Vladimir_Yalovy , @mark-piller ,

I am almost there.

Without the whereClause

I get a nice array of objects:

[
{
	"group_full": null,
	"subject": "Math",
	"created": 1618490273000,
	"timezone": "GMT+1",
	"group_capacity": 2,
	"slotsCount": 1,
	"slots_slug": "MAX2-GRADE 7-MATH-WED16:00-GMT-RAVINA",
	"ownerId": null,
	"tutor": "Ravina",
	"group_size": null,
	"grade": "Grade 7",
	"___class": "groups",
	"updated": 1618575879000,
	"objectId": "0490AC5C-F7BB-4E6F-BF55-291BFC996742",
	"group": "MAX2"
},
{
	"group_full": null,
	"subject": "ESL",
	"created": 1618496761000,
	"timezone": "GMT+2",
	"group_capacity": 3,
	"slotsCount": 1,
	"slots_slug": "MAX3-ESL A2-ESL-THU15:00-GMT-ASHLEIGH",
	"ownerId": null,
	"tutor": "Ashleigh",
	"group_size": null,
	"grade": "ESL A2",
	"___class": "groups",
	"updated": 1618557880000,
	"objectId": "091D2DC4-C3AD-4795-99E8-6A652EAE9B87",
		"group": "MAX3"
	}
]

But If I add a where clause such as slotsCount < 2

I get the following error:

{
	"code": 1111,
	"message": "Invalid use of group function"
}

Any thoughts on what I am doing wrong?

Hi @Andreas_Marinopoulos ,

Instead of where put slotsCount < 2 to having field

Regards,
Stanislaw

1 Like

Thanks :open_mouth: