How can I add a (seeding the foreig

2019-02-07 10:58发布

I have an edit form for a Post record, and I'm listing the Reviews associated with that Post in a ReferenceManyField/DataGrid (ie <ReferenceManyField target="post_id" reference="reviews">). Each Review has the foreign key post_id in the DB. This is all working fine, I have an edit and delete button for each Review row.

I need to add a 'Create Review' button for the Post form, such that the post_id field in the Create Review form is pre-populated with the current id of the Post. I'm not very expert in React/Redux.

2条回答
不美不萌又怎样
2楼-- · 2019-02-07 11:24

As @Gildas has suggested above, you need a custom component for that.

1) A custom create button that routes to a create page for the review. For this you should look at how the React Router Link component documentation as well as how Admin On Rest would allocate a route for instance /:reviewId/create

2) Create a custom input component that will prefill the ID when loaded. This should be part of the location key in the props passed to your page. Ask additional questions as comments and I will try and answer them.

React and Redux are really simple things when you get the hang of them

查看更多
Anthone
3楼-- · 2019-02-07 11:26

This is not possible directly for now: you'll have to create a custom component for that: documentation.

Someone tried to address this issue and even supplied a pull-request. Hopefully we'll be able to merge it soon: https://github.com/marmelab/admin-on-rest/pull/744

Edit: this might help https://marmelab.com/blog/2018/07/09/react-admin-tutorials-form-for-related-records.html

查看更多
登录 后发表回答