Filemaker: How to fetch list of related entities - filemaker

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.

Related

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.

Create One-to-One relationship based on PK of both tables

I'm really new to Entity Framework (currently using EF5) and vs2012 and am having difficulty trying to figure something out.
I have an .edmx that was generated from my database. It has two tables in it: Item and 3rdPartyItem. In short, the Item table is the main table for all the company items while the 3rdPartyItem table is a table that is used to hold additional attributes for items. This 3rdPartyItem table was created by an outside company and is used with their software for the company, so I can't mess with either table. What I'm trying to do is show a list of Items in a grid but I need to show a combination of all the fields for both tables. In vs2012, if I create a relationship and make it 'zero-to-one' (because for each record in the Item table, there doesn't necessarily have to be one in the 3rdPartyItem table), vs complains about not being mapped correctly. When I set the mapping, it then complains that there's multiple relationships. I did some research and found that you can't create a relationship with 2 primary keys, so I was thinking that was the problem. But how can I change the .edmx so that in code, I can access Items and 3rdPartyItem like so:
var items = dbContext.Items;
items.3rdPartyItem.SomeField <--field from 3rdPartyItem table.
not too sure if it's even possible, but it would be very, very helpful if so. Any ideas?
What you're looking for is table-per-type (TPT) mapping inheritance. You can view an MSDN walkthrough here (although you'd want your base type to be instantiable):
http://msdn.microsoft.com/en-us/data/jj618293.aspx

Where to place auditing fields?

In our shop, when we design a database, we typically include auditing attributes for each table (LastUpdateUser, LastUpdateDate, etc). This is common practice, however, I've noticed this becoming an increasing problem when you have tables that "inherit" from other tables, especially using tools such as the entity framework.
For example, if you have tables Customers and Employees, and those tables have a foreign key to table People, then in your entity / class model when you establish the inheritance, you need to change the names for the audit fields because they exist in both tables. Perhaps they need to become PersonLastUpdatedUser and PersonLastUpdatedDate, while the ones from Employees remain as simply LastUpdatedUser and LastUpdatedDate.
When designing tables for inheritance, do you put such audit fields in both tables, or do you just have them in the parent table and update the parent table whenever an attribute changes in a child table?
If you want to use inheritance than those attributes belong to parent table because the parent with related table forms single entity and you track auditing for whole entity. If you for any reason needs those attributes in both tables it should be the first warning that those tables are not good candidates for inheritance.
If you want true auditing, you create separate audit tables that are populated by triggers (never ever by the application or you will miss items that need to be audited).
and they shouw both the old and new value as well as the date and the user or application that made the change.
If you want a last updatedcolumn in each table (which I think is better than having it only in the parenta as that doesn't tell you anything about which of the tables changes last) and you want o use inheritance then you might need to create unique names by adding the table name to lastUpdated. So PersonLastUpdated and OrderLastUpdated, etc.
Or you don't use inheritance.

Removing Entities from Database table via Navigation Property using RIA Services and Entity Framework

I have 3 normalised tables consisting of Employees, Departments and EmployeesToDepartments. I wish to be able to assign an Employee to one or more Department, hence the link table (EmployeesToDepartments). I can successfully query the database and extract the full hierarchy of entities via the Navigation properties using
this.ObjectContext.Employees.Include("EmployeesToDepartments").Include("EmployeesToDepartments.Department")
plus the [Include] attribute in the metadata, thus allowing me to access the Departments for a given Employee. Upon trying to remove a link between an [Employee] and [Department] in the [EmployeesToDepartments] table I was given a Foreign Key Constrain error.
I have simplified my model to include just one navigation property between [Employees] and [EmployeesToDepartments]. A Foreign Key constraint between[Employees].[ID] and [EmployeesToDepartments].[IDEmployee] was preventing me from updating the EmployeesToDepartments table. With this removed via a Relationship setting I can now update the table. I can now execute the following code
foreach (var rel in _employee.EmployeesToDepartments)
{
_employee.EmployeesToDepartments.Remove(rel);
}
_domainContext.SubmitChanges();
without error.
I was expecting to see the entries in the RelEmployeesToDepartments with the IDEmployee to have been deleted. What I see in the table are the value 0 where the IDEmployee previously was.
Is it possible to force a DELETE statement to be issued? Am I misunderstanding the basic concepts here?
Any help would be much appreciated.
Removing entities in navigation property only breaks the link between entities. You have to delete from the EntitySet to achive what you want.
ex)
myDomainContext.EmployeeDepartments.Remove(employeeDepartmentToRemove);
myDomainContext.SubmitChanges();

Tough Sql Query problem involving family relationsships

i have a many to many table relationship that involves 2 logical tables.
Record table that joins to a relation table on primaryID
Second instance of record table that joins to the relation table on ReciprocalID
The purpose of this is to show family relations within the database. Each primary Record table has one or more rows in the relationtable that shows everyother family relationship this person has in the database.
I have been tasked with trying to make a contact list that involves displaying the names of each of the children that attend this school along with their parents and contact information.
I have gotten to a point where I am able to show the children under each parent, but now I have to find a way to merge these together.
Since I have no control over the design of this database(its Education Edge 7) I have made a separate database that holds my queries and views for my reports. The school I am doing this work for only has access to CR 8.5.
Right now I have my top group in CR as the lastname of the recordstable, my second group is on the fullname of the recordstable. I have a subreport that pulls in all the child records.
I have used a case when statement in my primary view(the one described above) to convert 'daughter' and 'son' to child and 'mother' or 'father' to parent.
hopefully this hasnt rambled too much. If you need anymore information just ask.
SELECT dbo.vwEA7RelationshipsTableView.PRIMARYID,
dbo.vwEA7RecordsTableView.LASTNAME AS PRIMARYLASTNAME,
dbo.vwEA7RecordsTableView.FIRSTNAME AS PRIMARYFIRSTNAME,
dbo.vwEA7RecordsTableView.NAMEFORDISPLAY AS PRIMARYNAME,
CASE dbo.vwEA7RelationshipsTableView.PRIMARYDESC
WHEN 'Father' THEN 'Parent'
WHEN 'Mother' THEN 'Parent'
WHEN 'Son' THEN 'Child'
WHEN'Daughter' THEN 'Child'
ELSE dbo.vwEA7RelationshipsTableView.PRIMARYDESC
END AS PRIMARYDESC,
dbo.vwEA7RelationshipsTableView.RELATIONID,
vwEA7RecordsTableView_1.LASTNAME AS RELATIONLASTNAME,
vwEA7RecordsTableView_1.NAMEFORDISPLAY AS RELATIONNAME,
dbo.vwEA7RelationshipsTableView.RELATIONDESC
FROM dbo.vwEA7RelationshipsTableView INNER JOIN
dbo.vwEA7RecordsTableView ON
dbo.vwEA7RelationshipsTableView.PRIMARYID = dbo.vwEA7RecordsTableView.ID INNER JOIN
dbo.vwEA7RecordsTableView AS vwEA7RecordsTableView_1 ON
dbo.vwEA7RelationshipsTableView.RELATIONID = vwEA7RecordsTableView_1.ID
TableViews are really just recreation of the primary tables from the main database.
I have solved this issue. My sql code was good, it was a matter of formatting my internal paramaters for Crystal as well as some creative grouping.