It is even possible to have a attribute with a dropdown sourced from another entity?

. Let's say I have an entity Department entity with a Car attribute. I want the user to enter the Car but to do say with a dropdown list (non editable), dynamically sourced from Cars entity. So user would only select an item and it would be saved. But mind you that this would be combination of 2 sources in one attribute - one from sourcing and the other one for the actual attribute to be saved. I have tried for an hour at least and kinda doubt it is possible but hopefully I'm wrong.
2 answers


This can be done by setting the associations in your domain model correctly see here Another option is to use microflows as the data source for your references.



In Mendix, the scenario you describe would be handled with associations. There is no need for a separate attribute on the Department entity to keep store the value of the Car association. Assuming each car can only belong to 1 department, you could do this as follows:

  • Create Department entity and Car entity
  • Create an association between them so that there is one Department for each car and each Department can have many cars
  • In a dataview of the cars entity, add a Reference Selector widget that points to this association. Note that you can select any attribute of the Department entity to display in this non-editable drop down box.

When the user selects a department for a car, he will be setting the association between these two entities. The relationship is between the two objects, not an individual attributes of the two objects. After this association is chosen and saved, you can access it, in a microflow for instance, by using a retrieve action against that association. If you want to display a list of cars for a given department, create a dataview of the department entity, and inside of that dataview, put a datagrid whose datasource is the cars entity over the association between cars and department. Then you can display whatever attributes of the car entity you choose in the datagrid (model, year, odometer reading, color, etc.)

Hope this helps,