Please use the Relations instead.
Download and install the sample component :
This tutorial can be read in 3 different ways :
Help : more informations about forks.
All forked files are in back-end. It makes it simplier for the tutorial, and also for the tests.
Study of Case : Travellers VISIT Cities
The N:M is linking 2 Lists:
The cross-reference (Xref) table is created to represent "a visit"
Try to reproduce the best you can the component layouts and pages. If you does not configure exactly the same it is not important. You can use modal boxes or not, you can add some more fields types (recommended) because it will help you to make some tests, and try some more possibilities.
IMPORTANT : The following configuration is really important for making the feature working :
Cascad integrity delete
When a City or a Traveller is deleted, all the reffered links must disappears. (most cases)
For every fk in the Xref table, choose 'FK integrity' = 'cascad' in the field properties.
Prepare the models
(This steps will be generated by Cook in future)
Step 1 : Create optimized profiles in the Xref model.
Those profiles will load the most minimalist datas, for improving performances.
a. Fork visits (list) model
b. Fork prepareQuery() : create 3 SQL profiles.
You are free to define the profiles you want. The 'object.' prefix is arbitary choosen.
Help : more informations about prepareQueryHeaders()
Step 2 : Auto-populate $cities in traveller
a. Fork the traveller (item) model
b. Create populateObjects()
Help : more informations about loadXref().
This will open the possibility to load the cross-reference list from an item, simply using state var (xref.cities)
The traveller item contains now a new array property ($cities), not physically in the database table, containing the Xref list.
Step 3 : Auto-populate $travellers in city
Same than previous, but oposite way
a. Fork the city (item) model
b. Create populateObjects()
Step 4 : Repeat steps 2 & 3 in the list models
a. Fork the travellers (list) model
b. Fork the cities (list) model
Objective 1 : Show the cross-reference list in a fly
The goal is to show a list of travellers in a city fly.
Step 1 : Ask to the model to load the travellers when loading this layout.
This layout is loaded in modal in our component sample.
a. Fork the city (item) view
b. Fork displayVisits()
Ask to the model to populate the travellers.
Step 2 : Display this list of travellers in the city fly layout.
In the sample component, the layout is called 'visits' and can load in modal (more convenient)
a. Fork the fly template file:
Objective 2 : Create a multi-select input in form.
Choosing cities from a traveller will create the links.
Step 1 : Prepare the model to save the recieved list of values to the N:M
This code is required in the item model after saving the item.
a. Fork traveller (item) model
b. Fork save() function
Help : more informations about updateXref().
Step 2 : Use JForms to instance the input
Use xref input type (since 2.6.3)
a. Fork the XML form file:
b. Empty the file and leave only the necessary in the fork:
Help : more informations about xref field.
Step 3 : Configure the view for sending the datas to the input
a. Fork the traveller (item) view:
b. Fork the traveller (item) form template:
Pass the dynamic list to JDom
Objective 3 : Embed a list within a list
Visited cities are added as a new column row
Step 1 : Ask the population of cities
a. Fork the travellers (list) view:
b. Fork displayDefault():
Step 2 : Render cities in the grid
a. Fork the grid template:
b. Add a table column (header + rows):
Objective 4 : Create N:1 (inversed Foreign Key)
This example does not permit to create countries 'on the fly'.
A country must be free of continent (FK) to appear in the list.
Step 1 : Prepare the model for creating optimized list
a. Fork countries (list) model:
b. Create a custom profile: object.default
Step 2 : Prepare the item model
a. Fork continent (item) model:
b. Auto-populate $countries in continent
c. Fork the save() function for recieving post array :
Step 3 : Load list of availables items
In case of N:1, the items already linked are not selectable. Even if the link is broken.
a. Prepare the continent (item) view
b. Fork the continent form template
Step 4 : N:1 Form
a. Fork the continent XML form
b. Instance the xref input:
Step 6 : Reproduce it for defining cities within the country form.
Facultative exercice :
Repeat the previous steps 1 to 4 to do the same in the city form :
Objective 5 : Mixed objects and multi-level
The goal is to load all availables datas from the continents list.
Step 1 : Preparation : propagate states with followers in each concerned model.
This definition of children states allows you to automatically follow the xref states to their children lists in cascad.
a. open the forked continents (list) models
b. Add states followers in populateObjects()
c. Repeat the operation for countries (item) model
Step 2 : Ask to load the cross referenced objects in the view
a. Fork the continents view file
b. Ask to the loader to populate all the following xref lists:
Step 3 : Build the template with the availables datas.
The template stucture will not be explained in this tutorial.
Dump the list to see all tree:
You can now build yout template as you want.
Have fun ;-)