Is it possible to have a subform that changes based on a indirectly related form? - forms

I have a database structure in this format: Relationship Structure
I have worked out how to attach a subform which displays children of a particular record:
Ex 1
Ex 2
However, I can't seem to find a way of having a subform listing the related grandchildren of a record. For example, all formulations that reference a particular material.

Don't bind your subform directly to the table, but bind it to a query instead.
Handle the Child - Grandchild relation in the query, and the parent-child relation in the form, like you're already familiar with.

Related

Filemaker: How to fetch list of related entities

I'm new to Filemaker, but have extensive SQL experience.
How do I add a list of children to my Filemaker layout, if I have a one-to-many relationship (a tree)? I would like to see for my current node all its children. Later I want to filter them as well.
Showing the parent is easy via the related field. But for the reverse it appears that I need to use scripts?
In SQL, I would write:
SELECT * from Element WHERE parent = {current_id};
You set up a relationship between the tables in the relationship graph using a primary key and foreign key arrangement. Then you add a portal to the related table occurrence on your main table layout. You can add filtering in the relationship itself or in the portal afterwards.
I advice you to check out this info from FileMaker on the subject.

Using FormBuilder to generate an edit form for a many-to-many join-entity with extra fields

tl;dr
I need an edit form for a uni-directional many-to-many relationship (doctrine), where the resulting join table has extra inherited properties. Is there a way to achieve this through the FormBuilder?
Entities
I have a uni-directional many-to-many relationship (doctrine), where the resulting join table has a relation to a third entity.
Form
The User edit-form should allow (un)crossing Deals easily through a checkbox, while also showing the relations' inherited fields from Discount. The discount's properties should be inherited from Deal by default and overridden on the UserDeal object if modified.
My approach
The way I have approached this, is by creating an auxiliary object UserDealState with two properties: a boolean active and a reference to the UserDeal. UserDealState has its own Type (checkbox and Discount fields).
I also added a transformer that converts the array of UserDeals to an array of UserDealStates, adding all the non-joined Deals (and setting active to false).
When I check the form inspector in the Symfony Profiler, I can see the transformation has taken place (the view data holds a collection of UserDealStates and is a much longer collection than the model data that holds a collection of UserDeals, which makes sense), but the form object only holds the amount of UserDealStates formViews that the original collection had of UserDeals had, not the much larger number it should.
Just to give a concrete example: say we have 10 Deals, and only one crossed UserDeals. On my form {{ form.userDeals.vars.value|length }} returns 10, {{ form.userDeals.children|length }} returns 1. Only one subform is rendered instead of 10.
Hera are my form-types: UserType, UserDealStateType, UserDealType, DiscountType.
Transformer: UserDealStateToUserDealTransformer
The question
How do you render a form with FormBuilder to edit the mapping between two entities in a many-to-many relationship and the relations' extra fields (as shown on the form mock-up above)?

Symfony2: Collection of dropdown select lists for a many-to-many relationship

The objective:
Having a many-to-many relation be displayed as a dynamic list of select inputs(single choice dropdown list)
User arrives on page with a single select field (multiple = false) populated with persisted entities and add/remove buttons. By clicking the add button, a new select field with the same options appears below the first, which adds a new entry in the M2M relation. By clicking remove the field disappears and the entry should be removed.
The model:
Two entities: User & Manager. A User has exactly one "special" Manager and unlimited normal Managers.
Managers manage unlimited users.To model this I have created two relationships for which the user is the "owner" (not sure how to translate this)
ManyToOne specialManager
ManyToMany normalManagers
I haven't created a many to many relationship with attribute "special" because the requirement is exactly one special manager and I wasn't sure if Symfony/Doctrine would cause problems down the line.
What I have:
I can display a multiple select field with the existing entities using Entity field type, as per the documentation. Functionally this is what I need, visually it is not.
I can also use the Collection field type to display a single text field, and add or remove more with JS, as per the documentation. Visually this is what I need, but The text fields (entity attribute) need to be replaced by choice field.
The question:
Before I continue digging, is there a simple way to achieve this list of select tags?
For anyone else who may eventually need a dynamic list of select fields:
I initially solved this issue by detaching the field(s) in event listeners, and handling the display/submission manually in the controller.
However I wasn't satisfied with this clunky solution and when I encountered the same need I used a second solution: creating an intermediary entity xxxChoice (in this case ManagerChoice) which is Mto1 inversed related to User and Mto1 related to Manager. Then by creating a ManagerChoiceType form with "Manager" entity field type I was able to easily display my collection of dropdown select lists.

How to use DBContext.Add/Attach (using EF CodeFirst 4.1) with nested opbjects

Problem: When adding an object "Order" to my dbcontext, all nested objects of the order gets "readded" to the database, though the nested objects is static data and only a reference shoudl be added in the database.
Example:
The database holds 0 orders, and 3 items.
I add one order with 2 items.
Now the database hold 1 order, and 5 items. The two items in the order has been "readded" to the database, even though the items had the right primary keys before db.SaveChanges().
I realize that i may be able to attach the existing items to the dbcontext before saving changes, but is that really the only way to go? Can't EF figure out that to item already exists when the primary key matches an existing item?
Does anyone know if this is different in the new version of EF CodeFirst?
No EF cannot figure if entities are existing one or new one - both Add and Attach commands are graph oriented operations. You call them on one entity in the graph and they traverse all relations (and their relations and so on) and perform the operation for them as well.
You must figure correct state of each entity in the graph for example by using:
dbContext.Orders.Add(newOrder);
foreach(var item in newOrder.Items) {
dbContext.Entry(item).State = EntityState.Unchanged;
}
dbContext.SaveChanges();
You can use the reverse operation by calling Attach(newOrder) and set the order to Added state. The main difference will come with independent associations (for example many-to-many relations). The first approach will correctly add new relation between order and each item whereas second will not unless you manually set each relation to Added state (and changing state for relations is more complex).

Ghost change my data after close form

I have a little databes in access. I make a few forms with sub forms and drop list(by query):
Steps of my creating form:
make form from table
delete all not PK or FK text box
create comboBox with store value to text box what I choase
create subForm and set Link Master Fields and child fields
design view:
This is form for table Task task have Fk: Project, peson etc. DropLists are connected tu subform for changing FK like project, person etc. So when I work i select in droplists what i want add to database and work with subForm. When I close this form, the first row in table change FK to last configuration on droplists.. Pleas how can I fix it?
It is quite possible to use a main form for selecting and updating subform records, but in this case it should not be a bound form.
To set up, for want of a better word, a linking form, unbind the main form, that is remove the record source and ensure the dropdowns (comboboxes) do not have control sources. I suggest you rename the dropdowns to cbo, to indicate that they are controls, not fields. The hidden controls should not be needed.
The value of a combobox is the value of the bound column. The Key or FK is the first item in your SELECT statement and the bound column is 1 (one) so the relevant Key or FK is the value of each comboboxe. You can set the link master fields to the names of controls so the Link Master Fields should be cbo_id_projekt;cbo_id_os_udaje;cbo_id_komponent;cbo_id_uloha.
As an aside, I generally avoid underscores, but each to their own.