title: Insert into relationship table using id created at user registration
body: <p>I have two tables as seen below</p>
  
  <p><img src="https://i.stack.imgur.com/PbF1h.png" alt="tables in database"></p>
  
  <p>The first table is for users and is populated via a registration form on the client side. When a new user is created, I need the second 'quotas' table to be populated with date, amount, and linked with the user id. The 'user_id' is used to pull the quotas information in a GET and display client side. I am having issues using the 'id' to populate the second table at the time of creation. I am using knex to make all queries. Would I be using join to link them in knex?</p>
  
  <p><strong>server</strong></p>
  
  <pre><code>hydrateRouter   // get all users
      .route('/api/user')
      .get((req, res) =&gt; {
          knexInstance
              .select('*')
              .from('hydrate_users')
              .then(results =&gt; {
                  res.json(results)
              })
      })
      .post(jsonParser, (req, res, next) =&gt; {  // register new users
          const { username, glasses } = req.body;
          const password = bcrypt.hashSync(req.body.password, 8);
          const newUser = { username, password, glasses };
          knexInstance
              .insert(newUser)
              .into('hydrate_users')
              .then(user =&gt; {
                  res.status(201).json(user);
              })
              .catch(next);
      })
  </code></pre>
  
  <p><strong>client</strong></p>
  
  <pre><code>export default class Register extends React.Component {
    constructor(props) {
      super(props);
      this.state = {
        username: '',
        password: '',
        glasses: 0
      }
    }
  
    handleSubmit(event) {
      event.preventDefault();
      fetch('http://localhost:8000/api/user', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify(this.state) 
      })
      .then(response =&gt; response.json())
      .then(responseJSON =&gt; {
        this.props.history.push('/login');
      })
    }
  </code></pre>
  
  <p><strong>server side route for displaying the water amount</strong></p>
  
  <pre><code>hydrateRouter
      .route('/api/user/waterconsumed/:user_id')  // display water consumed/day
      .all(requireAuth)
      .get((req, res, next) =&gt; {
          const {user_id} = req.params;
          knexInstance
              .from('hydrate_quotas')
              .select('amount')
              .where('user_id', user_id)
              .first()
              .then(water =&gt; {
                  res.json(water)
              })
              .catch(next)
      })
  </code></pre>
  
  <p>Thank you!</p>