bazzer747 25 Posted December 20, 2019 Does anybody know where I can find a (simple) example of setting up a Master-Detail on two tables (MSSQL in my case)? All I can find via the internet are either overly complicated examples or in non-English languages. The Help in Delphi/Firedac is the former and very difficult to follow. Share this post Link to post
Mark Williams 14 Posted January 8, 2020 (edited) You need a datasource that points to the master dataset. The Detail dataset needs to have its Mastersource property pointing to the dataSource (this step needs to be followed for both of the options specified below). You can then either: use the object inspector for the Detail dataset to define the relationship with the Master table (you need to set IndexFieldNames, MasterFields and as already mentioned MasterSource) or if the Detail dataset is an FDQuery you can define the relationship via a parameterized query entered into the SQL.Text property eg "SELECT [fields] FROM [mytable] WHERE [detail_table_foreign_key] = :[master_table_primary_key So in the latter case, if you had a master table called "employers" with aprimary key called "e_id" and a detail table called "employees" with a foreign key called "employer_id" your Detail query would need to be as follows: SELECT * FROM employees WHERE employer_id = :e_id The parameter is case sensitive. It must match precisely the name of the primary key field in the Master table. Edited January 8, 2020 by Mark Williams Update Share this post Link to post
Mark Williams 14 Posted January 8, 2020 BTW I meant to mention that you would probably have got a faster reply to this question if you had posted it in the FireDac sub-forum in Databases. Share this post Link to post
bazzer747 25 Posted January 9, 2020 Many thanks, thought this was just a data question rather than specific to FireDac, but noted for next time ... Share this post Link to post