How to associate objects?

Noob question here. I have a Domain model, with an association between customers and products. I want to see which customer ordered which products. How do I do that? Should I do something in my Microflows to assign a product to a customer (and associate these objects)? Or am I being stupid and should I add a clientID attribute in the product table (like with regular programming)? Thanks in advance.
4 answers

Mendix Rule one : forget IDs etc. They are no longer needed.

An Order is associated to a Customer. Make sure the *-side is at the order and the 1-side at the customer: Customers can place multiple orders.

In a Customer form (DataView Customer) create a Datagrid and choose the association between Customer and Order. Done.

If you have a list of orders, and create a new order add a dropdown to select a customer. Better create a select form because the number of customers is to big for a list.

You can follow the tutorials for this, might be a good idea.

Edit: Most widgets are placed in a table.



I'll take a stab at your initial question:

  1. Create a web form with a datagrid listing customers
  2. On the datagrid, right mouse click on the New button and have Mendix create the New/Edit form
  3. Open the generated New/Edit form, you will see a dataview for each customer
  4. Insert a row into the table in the dataview
  5. Insert a datagrid into the row you just created
  6. For datasource on the datagrid, select Database
  7. In the connector window at the bottom right hand side of the Modeler, the Customer entity should be the first entity listed.
  8. Expand the customer entity, then expand the customer_orders association
  9. Select the orders entity you see under this association

To get this to run, either delete the New/Edit buttons on the order datagrid within the customer window or have Mendix generate a form for you.

Hope that works - Mike


Thank you for your answer.

It just doesn't seem to work here.

The domain model is correct and as you described.

I also have the select/search box as you described. But the association doesn't work.

In which of the tutorials is this explained? I did all of the pizza mario ones, but this wasn't in them as far as I can remember.


Ah. Finally. After 3 hours of searching. I finally found out I had to add a row, otherwise you cannot add a data grid.

I am still trying to find out how to use a list of customers.