relation does not exist for multiple hasOne/belongsTo
See original GitHub issue#############
# Model
#############
Node = sequelize.define('node', {
id: {
type: Sequelize.INTEGER
primaryKey: true
}
}, {
timestamps: false
})
Beacon = sequelize.define('beacon', {
major: Sequelize.INTEGER
minor: Sequelize.INTEGER
}, {
timestamps: false
})
StaticDevice = sequelize.define('staticDevice' ,{
coordinates: Sequelize.GEOMETRY
type: Sequelize.ENUM('NODE', 'BEACON', 'BOTH')
battery: Sequelize.FLOAT
})
#############
# Relations
#############
StaticDevice.hasOne(Node)
StaticDevice.hasOne(Beacon)
#############
# sync
#############
StaticDevice.sync(force: true)
Node.sync(force: true)
Beacon.sync(force: true)
I get this error:
relation "staticDevices" does not exist
Why does this exists? im really lost, im doing exactly what the docs say.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
How can I solve "Relation 'a' is not instance of HasOne or ...
If the query executed, there exist error like this : Relation 'a' is not instance of HasOne or BelongsTo. How can I solve...
Read more >Eloquent: Relationships - The PHP Framework For Web Artisans
An example of a many-to-many relationship is a user that has many roles and those roles are also shared by other users in...
Read more >hasOne without belongsTo (i.e. one-way relationships)
I have two tables, let's call them property and address , plus some other tables. Every property has a foreign key which references...
Read more >hasOne Relation | LoopBack Documentation
A hasOne relation denotes a one-to-one connection of a model to another model through referential integrity. The referential integrity is enforced by a...
Read more >Difference between has one belongs to and has many
The only difference between hasOne and belongsTo is where the foreign key column is located. Let's say you have two entities: User and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
My bad, I guess i should be just using sequelize.sync(). Because i was doing as per the docs, copying the examples, but just syncing them manually.
However, please correct me if i am wrong, but i am just copying this directly from the docs http://docs.sequelizejs.com/en/latest/docs/associations/#creating-elements-of-a-belongsto-or-hasone-association
However, in the table, only products get create, no entry for users is created.
Node and Beacon have foreign key references to StaticDevice. Each call to
sync
is asyncronous, so when you fire them of like they were serial, the StaticDevice is not created at the time you try to create the two other tables. You can use promises (.then
), es7 (await
), or simplysequelize.sync()
to have sequelize handle syncing the tables in the correct orderClosing this issue, since it is neither a bug report nor a feature request.
For general sequelize questions, please use Slack, StackOverflow or Google groups.