What's the best way of implementing a many-to-many relationship?

Hi Everyone,

What’s the best way of implementing a many to many relationship in WeWeb?

I have a table of houses (e.g. 1 Acacia Av, etc) and a table of features (e.g. pool, yard, garage, etc). Each house can have many features, and each feature could apply to many houses.

I have an ‘edit house’ page. On this page, I want to allow users to add, edit and remove features. What’s the best way of implementing this?

(I’m sorry if I’ve missed existing content on this - please send me that way if so!)

Many thanks!

What are you using for your database/backend? Where are these tables stored?

One approach, you could create a join table. Each record in this table would just consist of ids. So you would have a row (record) like:
houseID. |. featureID
1_______________5
1_______________5
1_______________ 3
2_______________ 5

So house 1 have 3 features, two of those features are the same thing (id 5) and house 2 has one feature (id 5)

But there are a few ways of doing this depending on your DB/backend.

Hi twinsticks,

Thanks for your reply and sorry for my slow response.

I’m using Airtable for the backend - there are two tables there: ‘houses’ and ‘features’.

The relationship between the two is recorded in the houses table, using a ‘link to another record’ field, with the ability to select multiple features from the features table.

On the front end, I have an ‘edit house’ page, on which I have a datagrid of features. I want to be able to check/uncheck a checkbox in that datagrid to add/remove a feature to/from a house. I want to be able to pre-check the features already added when the ‘edit house’ page loads.

Thanks again for your help,

Ah, I am using Xano…

In the Airtable API, how are the linked records returned? What type are they? An array, and array of objects? that might help inn solving this.

I am making use of weWebs variables when pulling and combining data, you can do a lot with them like create arrays or objects or arras of objects… lol the list goes on.

You could look at pulling the data, combining it into a variable… modify that variable as you use/edit you application, and then pull the data from the variable when you want to save/write the changes back to Airtable?

That might be over complicating it… but I dont know how the Airtable works or provides this type of data sorry.