Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support creating nested resource in one mutation #14

Closed
wants to merge 2 commits into from

Conversation

lilac
Copy link

@lilac lilac commented Sep 19, 2018

Suppose we have two resources, post and question, where one post contains multiple questions. We want to create questions in the post create form. Following is the code.

export const PostCreate = (props) => (
    <Create {...props}>
        <SimpleForm redirect="show">
            <ReferenceInput source="agent.id" reference="Agent">
                <SelectInput optionText="name"/>
            </ReferenceInput>
            <TextInput source="title"/>
            <LongTextInput source="content"/>
            <ArrayInput source="questions.create" label="resources.Post.fields.questions">
                <SimpleFormIterator>
                    <TextInput source="title" label="resources.Question.fields.title"/>
                </SimpleFormIterator>
            </ArrayInput>
        </SimpleForm>
    </Create>
);

The magic here is the source="questions.create", which will map the array to a corresponding object in the mutation variable.

But this does not work with the current version. Rather, a simple fix is done here.

This PR also fixes the issue of DELETE_MANY and UPDATE_MANY not working.

@Weakky
Copy link
Owner

Weakky commented Sep 19, 2018

Hey there,

The DELETE_MANY and UPDATE_MANY mutations were removed because I planned to do it properly using deleteMany* and updateMany* batched mutations.
I guess we could indeed add the previous behavior meanwhile though.

Regarding what you have done for allowing nested create mutations, this could indeed solves #4, but I think we need to think more in-depth about it.

@lilac
Copy link
Author

lilac commented Sep 20, 2018

Glad to hear that

The DELETE_MANY and UPDATE_MANY mutations were removed because I planned to do it properly using deleteMany* and updateMany* batched mutations.

But these two features used to work, and the list UI indeed rely on it. When I upgraded to the latest release, I didn't realize it is a break change, the version does not imply that either. But suddenly the delete action on list pages of my production admin system stop working. Only after some debugging I realized it is due to the removal of these two changes. To keep it working, I had to add them back.

I understand this project is still early stage so break change will be introduced now and then. But I wish that we only break things when necessary. In this case, keep these two naive but working features there until a proper one is landed is better. Otherwise, everyone has to maintain their own forks to keep things working.

Regarding what you have done for allowing nested create mutations, this could indeed solves #4, but I think we need to think more in-depth about it.

Regarding this, glad to hear more on it. :-)

@Weakky
Copy link
Owner

Weakky commented Sep 20, 2018

I understand this project is still early stage so break change will be introduced now and then. But I wish that we only break things when necessary. In this case, keep these two naive but working features there until a proper one is landed is better.

The UPDATE_MANY and DELETE_MANY supports were removed before the first published version though. I did not spend time adding it again since then because I didn't know people were already relying on the library considering how WIP it is still.

I just upgraded ra-data-opencrud to add back support for these fetchType. Sorry for the inconvenience.

@lilac
Copy link
Author

lilac commented Sep 28, 2018

Alright, my fault. Thanks very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants