How to use foreign key to add data to my database in React

Asked
Active3 hr before
Viewed126 times

10 Answers

react
90%

The crux of the issue is that the addAlbum method is not returning the ID of the newly-created album, so there's no way to associate the songs and images with the album after the album is inserted. There are multiple ways to solve this, but were it me I would simply update the addAlbum method to return the album in its entirety after creation (that is, including the new UUID). A post might look like this:, What I'm pointing out is that your /albums API needs to return the id of the album after it's created. You need the id of the album to save songs/images to it, so return the id from the API. – benbotto Feb 18 '20 at 22:20 ,The album info and songs info get inserted on the same save button in React but how does the song know that the album_id is from that album id on the same page?

The crux of the issue is that the addAlbum method is not returning the ID of the newly-created album, so there's no way to associate the songs and images with the album after the album is inserted. There are multiple ways to solve this, but were it me I would simply update the addAlbum method to return the album in its entirety after creation (that is, including the new UUID). A post might look like this:

POST / albums HTTP / 1.1
Content - Type: application / json

{
   "title": "Dillon",
   "date": "2020-01-01T00:00:00.000Z",
   "description": "An awesome political protest album."
}
load more v
88%

Add to that, it turns out that buried in the job model is the full team model, which we use in the above code (this.props.job.team.name) but never abstract for other components. On the same page view we’re also making an API call for the current job’s team.,The Job module is a common module which we use in two different apps, but currentJobId is particular to the WebEx (Web Execution — please forgive the internal jargon) application and thus to its own module,The only props the component receives relates to UI state (e.g. “fetching jobs”), but it manages its own data retrieval internally, which means the component and its parent can be refactored or moved around safely.

The Nuclear docs offer a great strategy to creating API actions model by model. Since the wrapper we wrote around Thrift returns Promises, many of our model implementations are simple assignments:

exports.fetchAll = Thrift.enhanced.JobRole.index;
72%

I am trying to write form to insert record into database table. The table has some foreign keys so that means I should send IDs instead of NAME and similar.,Be the first to share what you think!,create some enums or similar, to have schema, in React and send it to server (Django rest in this case)

Pretag
 Pretag team - issue, fix, solve, resolve
65%

Pretag
 Pretag team - issue, fix, solve, resolve
75%

Using Repository to Add Data,Exploring Database Tables, TypeScript

Pretag
 Pretag team - issue, fix, solve, resolve
40%

The FOREIGN KEY constraint is a key used to link two tables together.,To allow naming of a FOREIGN KEY constraint, and for defining a FOREIGN KEY constraint on multiple columns, use the following SQL syntax:,To drop a FOREIGN KEY constraint, use the following SQL:

Pretag
 Pretag team - issue, fix, solve, resolve
22%

Pretag
 Pretag team - issue, fix, solve, resolve
60%

Scroll down to Foreign Keys section at the bottom and click on Add.,Click on Save to create the foreign key.,We are enforcing that the user_id column of todos table must be one of the values of id in users table.

Pretag
 Pretag team - issue, fix, solve, resolve
48%

Execute the below insert statement to add data into a table contact:,Following are the basic syntax used for defining a foreign key using CREATE TABLE OR ALTER TABLE statement in the MySQL:,Now, to delete this foreign key constraint from the contact table, execute the statement as below:

Pretag
 Pretag team - issue, fix, solve, resolve
23%

React-admin knows how to take advantage of these foreign keys to fetch references. Let’s see how the ListGuesser manages them by creating a new <Resource> for the /posts API endpoint:,React-admin runs in the browser, and relies on data it fetches from APIs.,The react-admin layout is already responsive. Try to resize your browser to see how the sidebar switches to a drawer on smaller screens.

yarn create react - app test - admin
cd test - admin /
   yarn add react - admin ra - data - json - server prop - types
yarn start
load more v

Other "react-undefined" queries related to "How to use foreign key to add data to my database in React"