• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

many-to-one relationship deletes linked data on save

Pangolin

New Member
Hi,

I'm new to fabrik. I've got my one-to-many relations working fine and my many-to-many ones, but am having trouble with many-to-one relationships.

My test data consists of two tables:performances and Shows

A performance contains an ID, a Date and is linked to a show with a Show_ID. The show contains an ID and a Show_Name.

e.g

Performances:
ID DATE SHOW_ID
1 11/06/15 1
2 12/06/15 1
3 13/06/15 2

Shows:
ID SHOW_NAME
1 Hairspray
2 Matilda


I link the performance to the show by joining the Performances.SHOW_ID to the Shows.ID in the Performance's list->data->joins.

So far so good. I now get:
Performances:
ID DATE SHOW_NAME
1 11/06/15 Hairspray
2 12/06/15 Hairspray
3 13/06/15 Matilda

When adding a new performance, I don't want to add a new show, I just want to select from the shows already there, so I set the Performances-Shows group's Layout->Show_Group option to "no".

Now when I try to add a new performance, it looks good: I just get a field to enter the date and one to enter the show ID. But when I click save, though the performance gets added with correct info, the show I selected has all its data wiped!

e.g. if I try to add to a new performance on 14/06/15 to the show with the SHOW_ID of 2, I get the following result:

Performances
ID DATE SHOW_NAME
1 11/06/15 Hairspray
2 12/06/15 Hairspray
3 13/06/15
4 14/06/15

Sorry for the essay, but can anyone see what I'm missing? This is driving me nuts!
 
I think this is a bug with Show_Group="no"
as the Performances form works as expected if I set Show_Group="Detail View Only" (though I then have to use css to get rid of the group from the detail view!)
 
Do you use list join feature? What are your settings there?
If your main list is on shows table and you set the list join as

From shows to performamces from id to show_id repeat yes
Then it should work as you expect.
BTW - read the needed tutorials in wiki
 
Thanks for replying, but this isn't what I'm trying to do nor is there a tutorial about many to one list joins.

The problems is with the Show_Group="no" option on the group created by the join. It causes the form to submit empty values for the group (rather than no values), effectively deleting the data in the joined table row.

Show_Group="Detail View Only" works (i.e causes the form to submit no values for the group, though as you would expect, you then have the group showing up in the detail view).
 
As per Jaanus's response, can you post a screenshot of your settings, and confirm which elements are PK's on their tables.

-- hugh
 
Sorry for the delay, the notification emails were going into my spam folder :(

Here are the settings, the primary keys on both tables are their IDs.
 

Attachments

  • listJoin.png
    listJoin.png
    53.4 KB · Views: 184
  • groupOptions.png
    groupOptions.png
    53.2 KB · Views: 188
I've discovered that though this works in the backend (setting the group to Detail Only View) in the front end this gives the following error when submitting the form:
------------------------------------------------
Forbidden

You don't have permission to access /performances/form/2/ on this server.
-------------------------------------------------

Though it only does this on my live server, on my testing server it works fine. For more details seethis forum post.
 
You should have set the list up vice versa.
The Shows list should be main list (if I understood right that a show could have many performances)
Then you add there a join:
from shows to performances from id to show_id
If you make this join repeatable then you can add many performances to one show within the same form.

Note: if you want to use form to submit/update joined data you can never set the list join from foreign key to primary key as the "from" element tries to submit/update the "to" element.
 
Are you saying that if I set up a one-to-many relationship, fabrik should automatically set up a many-to-one relationship in the other direction (because it doesn't seem to)? Or are you not understanding that I'm trying to get many-to-one relationships working?
 
I understand that you are loyal to the traditional usage of MySQL terms.
Just in the list join setup you have to forget it. "From id to parent_id" means there that the data from id field of main table would be written into parent_id of the child table during form submission.
But if in this case you still prefer to use Performences table as main one, then I suggest you to use just databasejoin element on this tables FK and not to make any list join (remove the existing as unneeded).

BTW - actually there is no differences between relations one-to-many and many-to-one
 
My example is simplified to show the problem I am trying to fix i.e that setting Layout->Show_Group=no doesn't work with a many-to-one list.

As I have said, I already have a work around: using Layout->Show_Group="Detail View Only" and nixing it from the detail view with CSS. Though it being fixed would be preferable.

BTW There is a massive difference between one-to-many and many-to-one, as your link says: they are opposites.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top