How do I create a UI for a Many-to-Many relationship? - cocoa

Can anyone advise on the best way to create a UI for establishing Many-to-Many relationships ?
Lets use an example from a previous question List <<-->> Patient.
I can create two separate Table Views, one for Lists and another for Patients which will allow the user to create Lists and Patients using two separately created Array Controllers (Lists and Patients), one linked to the List entity and other linked to the Patient entity.
Now I would like to be able to add/remove Patients from a List by creating an Table View that shows only Patients in the selected List. To do this I create a Array Controller (ListPatients) linked to the entity Patient with a Content Set binding to Lists.selection.patients.
Now things stop working nicely from here on....
If I bind a button to the ListPatients.add method then a NEW Patient gets created - there seems to be no way to simply add a NEW relationship between an existing Patient and the List.
Ideally what I would like to be able to do is to have a drop down list to select the Patient from.
Does anyone have any suggestions as to how best to do this without needing to create a new entity to represent this relationship.

What you need is a swapping Master-Detail view where either the List table or the Patient table is the Master or the Detail at any particular time.
When the List is the Master view, selecting a row will cause the Detail view to display all the Patient objects in the rowList.patients relationship. When the Patient is the Master view, selecting a row will cause the Detail view to display all the List objects in the rowPatient.lists relationship.
You really do want to break up the UI so the users always have a clear idea what the relationship is between the two tables. I would recommend a set of four tables, two each for each Master-Detail setup. That way, the user will also understand what they are looking at.
That will also make it easy to add new objects. Just put an add new button under the detail table and the user will understand that clicking it will add a new object to the relationship of the object selected in the Master view.

Related

PowerApps M:M relationships with additional attributes

I'm new to PowerApps. I'm creating a model-driven app. I've created some custom tables in the DataVerse - Information System, and Business Process. These tables have a M:M relationship. An Information System supports one or more Business Processes and a Business Process can use one or more Information Systems. I need to capture additional attributes that describe the nature of the relationship - what role does the Information System play with respect to the Business Process, and a score indicating how effective the Information System for that Business Process.
I've learned how to create M:M relationships using the built-in functionality in PowerApps but this does not permit me to define additional attributes for the relationship.
I've created my own M:M "middle" table and created M:1 joins from that table to each of the related tables. My "middle" table contains a lookup to each of the other tables and the additional attributes I need.
I need to know how to modify the default form for each of the related tables to include the "middle" table to enable a user to select a row from the "other" table and also to supply values for the additional attributes. I have searched for several days now and have not found any literature explaining how to do this.
I'm hoping there's someone who knows how to do this or can direct me to some literature about how to do it.
Thanks in advance for any assistance you can provide.
What you did is right, initially you created a native N:N relationship and for your need it should be manual N:N relationship which you created later.
You can add the subgrid of manual N:N intersect entity (two lookups and extra attributes) in both the main entities - this way you can create related records from either side. It can be a related navigation in the form instead of subgrid as well.
Read more

Filtering instances not related to the current contact

I have a custom entity Stuff and it contains a lookup to Contact. I created a 1:N relation with the latter as primary and the former as related entity.
On the Contact's form I added a subgrid and I only wish to list the instances of Stuff that have the lookup pointing to the currently viewed Contact. However, when I choose Only Related Records, the custom entity isn't in the list (despite it being related via the 1:N relation).
So, I'm using All Record Types, instead, but that shows all the instances of Stuff and not, as I wish, only those that are related to the currently viewed member.
So, what's the best course of action here? Should I do something with the relation? Or build a custom filter in JavaScript? How can I make the Stuff related to Contact if it's at all possible?
The image below shows the available conditions for the related entities. I notice that none of them relates to Contact, though. Do I need to activate it somehow or am I approaching it from a totally wrong angle?
So to give you more detail, you add the grid on the form:
(This is coming from the contact Form edit, after you press add subgrid)
you select there only related records, this are the stuff record i created:
As you can see only 3 of them has a lookup pointing to a valid contact, from there if you look at the grid, is showing only the related ones as you selected during the grid creation:
In any case i update the answer this is how the relationship is defined, and is a simple lookup created from the stuff entity:

Two DropDownList and EntityFramework

I need to create the methods (or another that you recommended I) so as to filter the data in two dropdownlist. The scenario I have is as follows:
1) Business Class for database access (CRUD)
2) Two DropDownList (inside a GridView)
The first presents the Groups Article while the second items, according to the choice made in the first the second is populated.
The database tables consist of the following:
1) Table Groups
2) Table of Related Items
The reports of the tables are one-to-many, or one group can have many articles, both have their own primary key.
What suggestions do you give me?
Thank you all,
Ricardo.
i think you just need two methods:
- GetAllGroups(): That call Entity framework to get all groups from db
- GetArticlesByGroupID(<<groupID>>): that get articles from db based on what groups was chosen
the main flow of your program will be:
- after form is initialized, you can method GetAllGroups() and populate into first dropdownlist
- in event selected changed of first dropdownlist and call method GetArticleByGroupID(...) and populate into second dropdownlist
that all.
from Entity Framework view: you need to create any needed Object or DTO, such as groupDTO, ArticleDTO, GroupRespository... or something like that
hope can help you

CoreData SQLite - Data looks deleted but in fact, it is not

The app allows to manage a list of Suppliers and a list of Products available from those Suppliers. Data model contains 2 entities: Supplier and Product.
Supplier has a 1-to-many relation to Product, with delete rule set to Cascade (as I don't want to keep records of a supplier's products if it gets put out of business). Product has default relationship settings.
In IB, I have 2 array controllers. One points to the Supplier entity, with Parameters: MOC bound to AppDelegate and MKP=managedObjectContext. The other points to the Product entity, with Parameters: MOC bound to AppDelegate and MKP=managedObjectContext, and with Controller Content: Content Set bound to Suppliers array controller, CK=selection and MKP=name_of_relation.
On the interface I have 2 NSTableViews for Suppliers and Products, and buttons to Add/Remove from the tables. When I select a Supplier, only its specific Products are displayed on the Products table. When I delete a product, the product disappears from the table. It works as intended.
I thought it was working fine, until the day where I was curious to see how CoreData actually manages the data fields and tables inside the SQLite database. So I opened it using the SQLiteManager add-on in Firefox and... horror! I see that the Products are not deleted. The data are still there! Only the reference to the Supplier was deleted and that's why it doesn't appear anymore in the table, leading me to think that it had been correctly deleted.
What did I do wrong? Is it something with the Content Set bindings?
Thanks for advice.
I just ran a test on this and the result was that the relationship entities where completely deleted from the sqlite database. I think you need to check your cascading settings again exactly in IB. Did you make sure you have a save: statement?

Making entity framework treat views with many-to-many relationships, like it does tables with many-to-many relationships

I have three views that I've manually created in the DB.
First view is "Region", the second is "FIPS" and the last is a many-to-many between them called "Region2FIPS". These are all views, and I only need read access the data, so I'm not worried about having updateable views.
I have added each of these views to Entity Framework, and created the appropriate associations between them.
Region to Region2FIPS is a 1 to many.
FIPS to Region2FIPS is a 1 to many.
The "Region2FIPS" view contains only two columns, one called "FIPSID" the other "RegionID". These column are associated with their respective views in the relationships I defined above.
When this type of association is made on tables in the DB, Entity Framework knows that it is a many-to-many relationship and it creates a navigation property on "Region" called "FIPS" that I can use to navigate through the child collection of FIPS. It does likewise for "FIPS" to "Region".
However, when done manually, with views, it does not exhibit that behavior. Instead, my "Region" object has a collection of "Region2FIPS" objects, which each have a navigation property called "FIPS" which is of type "FIPS". And my "FIPS" object has a collection of "Region2FIPS" objects, which each have a navigation property called "Regions" of type "Region".
I assume this has something to do with the fact that I can't create foreign key references on the views, so entity framework doesn't realize the many-to-many relationship. But I thought that if I manually created the many-to-many relationship between the views it would recognize it and properly handle the navigation between the types. Is there a way for me to force it to do this?
It's possible, but the designer doesn't really help you here. You have to do the mapping manually.
One fairly easy way is to use Code First mapping. But this means your model has to be Code First to begin with. If you're writing a new model, just do that.
If you're using DB First mapping, however, you will have to do the mapping manually. Your SSDL will probably already be correct, once you define the "primary keys" of the views. You would then have to remove the "Region2FIPS" objects from the CSDL (not just from the designer!) and manually patch up the MSL.
Perhaps the easiest way to do this would be to use the designer to automatically map real DB tables (not views) with a similar schema and then replace the table names with view names in the EDMX, using the XML editor.

Resources