user.getAssociations not working
See original GitHub issueI have a User and a Trip model. Users belong to many Trips and Trips belong to many Users (both through the UserTrip table). I’m using v3.13.0 with postgres.
I can call trip.getUsers(), but when I try user.getTrips() I get the following error
Unhandled rejection TypeError: undefined is not a function
Models
User
"use strict";
module.exports = function(sequelize, DataTypes) {
var User = sequelize.passportLocalSequelize.defineUser(sequelize, {
// login stuff
email: DataTypes.STRING(254),
hash: DataTypes.TEXT,
salt: DataTypes.STRING(255),
// personal info
first_name: DataTypes.STRING,
last_name: DataTypes.STRING,
phone: DataTypes.STRING(12), //length needed for international numbers
address: DataTypes.STRING,
city: DataTypes.STRING,
state: DataTypes.STRING,
country: DataTypes.STRING,
zip: DataTypes.STRING,
birthday: DataTypes.DATEONLY,
// app shit
customerId:DataTypes.STRING(2000),
role: DataTypes.STRING,
credits: DataTypes.INTEGER,
referral_id: DataTypes.STRING,
referral_code: DataTypes.STRING
}, {
classMethods: {
associate: function(models) {
User.belongsToMany(models.Trip, {through: 'UserTrip'})
}
}
});
return User;
};
Trip
"use strict";
module.exports = function(sequelize, DataTypes) {
var Trip = sequelize.define("Trip", {
// waypoint info
start_address: DataTypes.TEXT,
start_point: DataTypes.STRING,
destination_address: DataTypes.TEXT,
destination_point: DataTypes.STRING,
departure_time: DataTypes.DATE,
return_time: DataTypes.DATE,
// options
is_private: DataTypes.BOOLEAN,
ride_type: DataTypes.TEXT,
max_passenger: DataTypes.INTEGER,
food_drink: DataTypes.BOOLEAN,
// non-visible
passenger_count: DataTypes.INTEGER,
estimated_cost: DataTypes.DECIMAL(10,2),
actual_cost: DataTypes.DECIMAL(10,2),
is_completed: DataTypes.BOOLEAN,
organizer_id: DataTypes.INTEGER
}, {
classMethods: {
associate: function(models) {
Trip.belongsToMany(models.User, {through: 'UserTrip'});
Trip.belongsTo(models.Event);
}
}
});
return Trip;
};
I can’t for the life of me figure out what I’m doing wrong. I would massively appreciate any insight you might have– Let me know if there’s anything I’ve left out that would help solve the issue
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
UserPrincipal.GetGroups fails with unknown error
I have the issue you describe. I have the problem getting groups when user DN contains "/". Can you tell me what's the...
Read more >PK51257: ENABLE HONORING USER OR GROUP FILTER ...
When LDAP is used as user registry, in getGroups and getUsers when a full DN is used, the code searches for the DN...
Read more >Flickr Services: Flickr API: flickr.people.getGroups
flickr.people.getGroups. Returns the list of groups a user is a member of. ... 1: User not found: The user id passed did not...
Read more >Users in User Group Not Show as Community Members
When we add users to a group - we can call it MyCommunityUsers and then add that group to a community, the portlets...
Read more >User.Principal.GetGroups() lookup wrong DC - Microsoft Q&A
I work for a customer whose program makes a query on the groups of an AD. Until the time the DC was changed,...
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
The only time associate gets called is in my models/index.js file
I am having a similar issue, none of the association methods are working for me. I am new to Sequelize.
I console logged inside the if statement in index.js and they are both being associated. They both have all the methods listed in the prototype chain. If I call them with
db.User.getGroups()
I get “is not a function” if i calldb.User.prototype.getGroups()
I get "Executing (default): SHOW INDEX FROM ‘User Group’ FROM ‘My Database Name’ and then “Unhandled rejection TypeError"Cannot read property ‘id’ of undefined”Any help would be appreciated.