Add detail record in set master detail

hello @johnny
Is it possible to add details in master-detail mode with a single field referring to the master table and set it to hidden?

For now, it seems that the variable “master_id” is only sent in the list datatable mode, and it is not sent in the add_form and edit form modes.

regards
Nasrul

1 Like

Hello @nasrul ,

I see what you mean. Since this is a new area, I haven’t thought about that. I will revisit this and let you know for any solutions or at least a work-around if any.

Regards
Johnny

1 Like

Thank you very much @johnny
I will wait for your updates. Grocery CRUD has been very helpful for me in creating programs.
I hope you are always in good health.

Regards
Nasrul

1 Like

Hello @nasrul ,

I am very glad to announce you that at the latest version (3.0.16) we now have the ability to take the master_id at insert/update/clone forms.

A simple example of how to do that in the detailed CRUD is the below code:

$crud->fieldType('customerNumber', 'hidden');

$crud->callbackBeforeInsert(function ($stateParameters) {

    if (!empty($_POST['master_id'])) {
        if (is_numeric($_POST['master_id'])) {
            $stateParameters->data['customerNumber'] = $_POST['master_id'];
        } else {
            throw new InvalidArgumentException("Invalid argument for the field 'master_id'");
        }
    }

    return $stateParameters;
});

So basically you need to use the callbackBeforeInsert and make sure that you have the fieldType as hidden so the insert form will not filter it.

If you are using Composer then I have more good news for you since now we have moved to our private composer server. In short that means that you no longer need to download any zip file for update :slight_smile:

For more you can check the blog post: Grocery CRUD Private Composer | Grocery CRUD Blog

Let me know if that worked for you.

Regards
Johnny

sorry @johnny for late response
I am busy with another project using a different programming language, but I have tried it, and it works very well.
Thank you, Jonny, for your hard work.

Regards
Nasrul

1 Like

Hello @nasrul and happy new year :partying_face:,

If you don’t mind (I am adding this post publicly so maybe others may have some input) what language are you using? I was thinking to extend Grocery CRUD on other languages as well but with different architecture (e.g. having it in the cloud). Do you think that something like that would be beneficial for your projects?

Regards
Johnny

Hello @johnny , and Happy New Year to you as well!
I am using ASP.NET Core with C#.
Certainly, if Grocery CRUD could be used with other languages, it would be very helpful for programmers.
Using Grocery CRUD allows me to focus on completing the business processes of the application without spending too much time implementing CRUD operations for each table in the database.
Thank you very much, @johnny , for your hard work

Regards
Nasrul

1 Like