-
Notifications
You must be signed in to change notification settings - Fork 1
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
Set up customer -> flight relation to allow flights to have many customers #17
Comments
Edited, thanks. models.Flights.hasMany(models.Customers)
models.Customers.belongsTo(models.Flights) https://stackoverflow.com/questions/20290815/belongsto-vs-hasmany-in-sequelize-js So I wonder what is the exact different between these cases? |
Ah yeah, I see what you're saying - that can be confusing. If you have The difference is in how you can use the model instances. If you set up the hasMany relation on Flights, then you can easily get all customers for a flight model using the built-in functions that sequelize adds ( |
nigerian-airlines/server/database/models/index.js
Line 10 in bb60785
Right now, the relation between customer and flight is a one-to-one relation (using
belongsTo
). I think that the app could support having multiple customers per flight, which would mean that this relation has to change to a one-to-many relation.Here's the sequelize docs on one-to-many relations:
http://docs.sequelizejs.com/manual/tutorial/associations.html#one-to-many-associations-hasmany-
The simplest way would be to use
hasMany
, to connect one source (here, the Flight) to multiple targets (Customers):models.Flights.hasMany(models.Customers)
The text was updated successfully, but these errors were encountered: