Closed kevinresol closed 6 years ago
That's a limitation I've known about for some time but have avoided fixing.
I guess the time has come to fix it.
Would being able to specify a custom table name be an adequate solution?
@:table("event_participating_users") public var participatingUsers:ManyToMany<Event,User>
@:table("event_invited_users") public var invitedUsers:ManyToMany<Event,User>
Or do you have another suggestion? The extra metadata feels verbose so if there's a more elegant solution I'm open to it.
metadata is great for giving flexibility. If user does not specify table name, can we simply use the var
name? Like _join_event_user_participatingUsers
or is it possible to use typedef
?
typedef ParticipatingUser = User;
typedef InvitedUser = User;
// Event.hx
public var participatingUsers:ManyToMany<Event, ParticipatingUser>;
public var invitedUsers:ManyToMany<Event, InvitedUser>;
// User.hx
public var participatedEvents:ManyToMany<ParticipatingUser, Event>;
public var beingInvitedEvents:ManyToMany<InvitedUser, Event>;
Using the var name won't work because usually you'll use different var names on each of the models:
// Event.hx - would create tables "_join_event_user_participatingUsers" and "_join_event_user_invitedUsers"
public var participatingUsers:ManyToMany<User, ParticipatingUser>;
public var invitedUsers:ManyToMany<User, InvitedUser>;
// User.hx - would create tables "_join_event_user_participatedEvents" and "_join_event_user_beingInvitedEvents"
public var participatedEvents:ManyToMany<User, Event>;
public var beingInvitedEvents:ManyToMany<User, Event>;
The typedef idea is interesting. It could break unexpectedly if people are using typedef aliases, which I sometimes do when I rename a model:
// We renamed the model StaffMember, but I wanted to leave the typedef in place to prevent breaking code.
typedef Teacher = StaffMember;
I'm leaning towards the metadata idea unless you object... you are right that it gives you full flexibility, and I doubt it will be required often enough that you end up resenting writing the extra few characters.
And on the plus side it should be fairly easy to implement.
ok, agreed
Cleaning up my old issues and I think this is no longer needed.
I am having a
Event
object which would like to have the following fieldsBut seems that the macro only generates one
Join_Event_User
table?