Sails.js One Way Association

I am trying to relate two MySQL tables in sails js. I have read the documentation on this subject found here.

The error I am receiving:

error: Sending 500 ("Server Error") response:
Error (E_UNKNOWN) :: Encountered an unexpected error
: ER_BAD_FIELD_ERROR: Unknown column 'user.character' in 'field list'..

I have a Characters.js and a User.js

User.js model contains:

character: { model: 'Characters' }

and Characters.js contains:

owner: { model: 'User' }

Can anyone give me a tip on how to get these two tables talking? Thanks.

It may be that your user table is missing the column which references the characters table.

What might have happened is that you changed the model and the database isn't reflecting the changes. If you have not disabled the auto migrate for the models, you should be able to delete the existing MySql tables and when you re lift they should be re made with the proper columns.

Try:

  1. Dropping the user and the characters table
  2. re-lift sails

Hopefully that helps you!

Just FYI, what you're doing is a one-to-one association.

The error could also arise depending on how you're trying to grab user.character. If dropping the tables and recreating upon sails lift doesn't work, since you didn't post the code that was causing this error, then check if you're using populate correctly:

User.findOne.where({ criteria_goes_here }).populate('character').exec(function (err, user) {
  var character = user.character; // your character model instance
}