Hi, i'm new to your Aurelius and try to create an many-to-many association.
I have User and UserGroups (Admin,Orders,Sales..). Multiple groups can be assigned to users.
And, of course, a group can be defined for multiple users.
My Classes:
TUser = Class;
TUserList = TList<TUser>;
TUserGroup = Class;
TUserGroupList = TList<TUserGroup>;
TUser_UserGroup = Class;
TUser_UserGroupList = TList<TUser_UserGroup>;
[Entity]
[Table('User')]
[Id('FID', TIdGenerator.IdentityOrSequence)]
TUser = class
private
FID: Integer;
FUsername: String;
FUser_UserGroupList: TUser_UserGroupList;
public
constructor create; overload;
constructor create(aUsername: string); overload;
destructor destroy; override;
property Id: Integer read FID write FID;
property Username: String read FUsername write FUsername;
[ManyValuedAssociation([], CascadeTypeAll, 'FUser')]
property UserGroupList: TUser_UserGroupList read FUser_UserGroupList
write FUser_UserGroupList;
end;
[Entity]
[Table('User_UserGroup')]
[Id('FID', TIdGenerator.IdentityOrSequence)]
TUser_UserGroup = class
private
[Column('ID', [TColumnProp.Required])]
FID: Integer;
[Association([TAssociationProp.Lazy], [])]
[JoinColumn('ID_UserGroup', [], 'ID')]
FUserGroup: Proxy<TUserGroup>;
[Association([TAssociationProp.Lazy], [])]
[JoinColumn('ID_User', [], 'ID')]
FUser: Proxy<TUser>;
function getUser: TUser;
function getUserGroup: TUserGroup;
procedure setUser(const Value: TUser);
procedure setUserGroup(const Value: TUserGroup);
public
constructor create(aUser: TUser; aUserGroup: TUserGroup);
property Id: Integer read FID write FID;
property UserGroup: TUserGroup read getUserGroup write setUserGroup;
property User: TUser read getUser write setUser;
end;
[Entity]
[Table('UserGroup')]
[Id('FID', TIdGenerator.IdentityOrSequence)]
TUserGroup = class
private
FID: Integer;
FName: string;
FUser_UserGroupList: TUser_UserGroupList;
public
constructor create; overload;
constructor create(aName: string); overload;
destructor destroy; override;
property Id: Integer read FID write FID;
property Name: string read FName write FName;
[ManyValuedAssociation([], CascadeTypeAll, 'FUserGroup')]
property UserGroupList: TUser_UserGroupList read FUser_UserGroupList
write FUser_UserGroupList;
end;
When assign a group to a User, i create the association-class User_UserGroup with my own constructor for
a single-line-statement.
Manager.Save(TUser_UserGroup.create(myUser,myUserGroup));
Manager.Flush;
After that the lists ob myUser and myUserGroup are not updated.
Is this a legal way to do association?
I have to call manager.Update<myUser> and all works fine.
On the other side when i do this:
myUser_UserGroup := TUser_UserGroup.create;
myUser.UserGroupList.add(myUser_UserGroup);
myUserGroup.UserGroupList.add(myUser_UserGroup);
Manager.Flush;
myUser_UserGroup is empty until Manager.Refresh<myUser_UserGroup>
The objectmanager does not link that associations himself?
Is it a bug or a feature?