48
Views
7
Comments
Solved
List in Database Record

Hi,

 I'm building an app with outsystems for a school project. There are products and transactions. I'd like to have a List with all products, that have been purchased in the Record of the transaction. For this I think I need a List entity attribute, which I can't add.
Maybe some of you know a way of doing this.

Thanks in advanse and sorry for my bad spelling.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Hi Silas,

You misunderstand how a relational database works. In such a database (and OutSystems uses a relational database), you cannot store lists of things in an attribute. Instead, you create a one-to-many or a many-to-many relationship in your database.

A one-to-many relationship is a relationship where one main item can relate to ("contain", if you like) zero to infinite sub items. E.g. if you have departments and employees, and an employee can work only in a single department, you have a 1 (department) to many (employees) relationship. The typical way to model this in your database is to add the Identifier of the main item to the table (entity) of the sub item. So add a DepartmentId to the Employee table.

A many-to-many relationship is one where one main item can relate to zero to infinite sub items, but each sub item can relate to zero to infinite main items. For example, you have Courses (the main item) and Students (the sub item), but besides each Course having many Students, each Student can be in more than one Course. To model this in a database, you add a linking table (a.k.a. associative entity), which is an entity that contains both a CourseId and a StudentId. For each course, you create as many records as there are students in that course. If you want to find all students for a specific course, you query all records in the linkin table with the CourseId for the course, and join the linking table with the Student entity on the StudentId.

Since you have Transactions (main item) and Products (sub item), but Products can obviously be in more than one Transaction, you have a many-to-many relationship, and need to create a linking table as described above.

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Hi,

You have to say which application type you use, Traditional, reactive or mobile.

The reply people will give depend on this.

The answer to your question: you need to define the entities Product and Transaction with an attribute for each piece of information you need to store. In Transaction entity you add ProductId as attribute to set a relation between the two entities.

Then drag the transaction entity on a UI flow to generate a list and detail screen.

That should be it.

Regards,

Daniel 

2023-02-20 10-34-29
Fahad khan

that is correct 

UserImage.jpg
Aman Singh Rajput

Hello @Silas Hille,

Adding Daniel's reply. You need to create a many-to-many relationship between Product and Transactions. Refer to the documentation below on how to achieve this.

Click here for documentation

UserImage.jpg
Silas Hille

Thanks. I'm using a Reactive Web app. With List i mean, that I can store a List of ProductId e.g. 1,4,67
in the Record of the transaction.

UserImage.jpg
Puja Rani


Hi @Silas Hille , You can have two separate Entities Product and Transaction. In Transaction entity you can add productId attribute to create a relationship between two entity and then can store the List of ProductId. 


However, I would also suggest you to go through the Data Model training course for Reactive Web app.

Regards,

Puja

UserImage.jpg
Silas Hille

Thanks, but how can you add an entire List of Ids. When I try to add a Product Identifier List, it says "Product Identifier required instead of Product Identifier List".

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Hi Silas,

You misunderstand how a relational database works. In such a database (and OutSystems uses a relational database), you cannot store lists of things in an attribute. Instead, you create a one-to-many or a many-to-many relationship in your database.

A one-to-many relationship is a relationship where one main item can relate to ("contain", if you like) zero to infinite sub items. E.g. if you have departments and employees, and an employee can work only in a single department, you have a 1 (department) to many (employees) relationship. The typical way to model this in your database is to add the Identifier of the main item to the table (entity) of the sub item. So add a DepartmentId to the Employee table.

A many-to-many relationship is one where one main item can relate to zero to infinite sub items, but each sub item can relate to zero to infinite main items. For example, you have Courses (the main item) and Students (the sub item), but besides each Course having many Students, each Student can be in more than one Course. To model this in a database, you add a linking table (a.k.a. associative entity), which is an entity that contains both a CourseId and a StudentId. For each course, you create as many records as there are students in that course. If you want to find all students for a specific course, you query all records in the linkin table with the CourseId for the course, and join the linking table with the Student entity on the StudentId.

Since you have Transactions (main item) and Products (sub item), but Products can obviously be in more than one Transaction, you have a many-to-many relationship, and need to create a linking table as described above.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.