Closed meladam20 closed 1 year ago
Show me code and show me what your server is receiving
@JsonSerializable()
@DataRepository([JsonServerAdapter])
class User extends DataModel
User( {this.id, required this.firstName, required this.lastName, required this.email, required this.password, required this.role});
@override int compareTo(User other) => firstName.compareTo(other.firstName);
Map<String, dynamic> toJson() => _$UserToJson(this);
factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json); }
class Role extends DataModel
Role({this.id, required this.libelleRole});
//@override //int compareTo(User other) => firstName.compareTo(other.firstName);
Map<String, dynamic> toJson() => _$RoleToJson(this);
factory Role.fromJson(Map<String, dynamic> json) => _$RoleFromJson(json); }
// Function de save data
Future register() async { final developerRole = Role(libelleRole: 'developpeur');
User(
firstName: firstName.text,
lastName: lastName.text,
email: email.text,
password: password.text,
role: BelongsTo(developerRole)).save();
}
// Nodejs server code
const UserSchema = new mongoose.Schema({ //_id: Number, firstName: { type: String, required: true }, lastName: { type: String, required: true }, email: { type: String, required: true }, password: { type: String, required: true }, role: { type: 'ObjectId', ref: 'Role', } } );
///////////////// req.body data
[ { firstName: 'az', lastName: 'er', email: 'df@gmail.com', password: '$2a$10$frDD9zJ6aphuMaTRuu4ihOQENk/SF8Vu7hyaIuXGRCTA3/drv3e1e' } ]
The role field doesn't exist and i don't know why.
developerRole
has no ID
Hello, I'm using BelongsTo but in my nodejs server i can't get the value with req.body. Please tell me how to get the value of BelongsTo relationship.