How to defination many-to-many relation? readme sample not work.
MiYogurt opened this issue · comments
I try write all defination in one file,but the migaration only run once. like, only migration user
table.
If definition by another file, the abstract class name start with _
,is private variable。this is unavailable。 If i use genated model name,the build_runner
aserted the variable type is dynamic
。
Maybe need more detailed documentation。
like how to definition rbac model.
user.dart
@serializable
@orm
abstract class _User extends Model {
String get username;
String get password;
String get email;
DateTime get joinDate;
List<UserRole> get userRoles;
List<Role> get roles => userRoles.map((m) => m.role).toList();
List<Permission> get permissions => roles.fold([],(acc, role){
acc.addAll(role.permissions);
return acc;
});
bool can(String resource, String type, [bool check(Permission p)]) {
var permission = permissions.firstWhere((p){
return p.resource.contains(resource) && type.contains(type);
});
if (check == null) {
return permission != null ? true : false;
}
return check(permission);
}
}
user_role.dart
@serializable
@orm
abstract class _UserRole extends Model {
@belongsTo
User get user;
@belongsTo
Role get role;
}
role.dart
@serializable
@orm
abstract class _Role extends Model {
String get name;
List<UserRole> get userRoles;
List<User> get users => userRoles.map((ur) => ur.user).toList();
List<RolePermission> get rolePermissiong;
List<Permission> get permissions => rolePermissiong.map((m) => m.permission).toList();
}
permission.dart
@serializable
@orm
abstract class _Permission extends Model {
String get resource;
String get type;
DateTime get end;
List<RolePermission> get rolePermissiong;
List<Role> get roles => rolePermissiong.map((m) => m.role).toList();
}
role_permission.dart
@serializable
@orm
abstract class _RolePermission extends Model {
@belongsTo
Role get role;
@belongsTo
Permission get permission;
}
whatever i use serializable or @Serializable(autoIdAndDateFields: false)
the user_role
and role_permission
will not be generator migration.
- Please bear with me for a little bit - the ORM is still in development (as marked by
-dev
suffix in the version). Join the Angel chat for continuous updates: https://gitter.im/angel_dart/discussion - As of the latest version of
angel_migration_runner
, having multiple models in one file should be supported. I might need to investigate this more, but runpub upgrade angel_migration_runner
first. - As of recent updates to
angel_serialize_generator
,@Serializable(autoIdAndDateFields: false)
is no longer necessary.
ok。thx,i will continuous follow-up.