#Vapor-Fluent and Many-to-Many Relations?

1 messages · Page 1 of 1 (latest)

frosty trellis
#

I have a SQL schema (PostgreSQL) that looks like this:

CREATE TABLE LinkedUserProfile (
user_profile_id int8 NOT NULL,
target_user_profile_id int8 NOT NULL,
createdDate timestamp with time zone NOT NULL,
PRIMARY KEY (user_profile_id,
target_user_profile_id));
I want to generate a Fluent class for this table. In JPA, this would be simple. My code would look like this:

@Embeddable
public class LinkedUserProfileKey implements Serializable {

private static final long serialVersionUID = 5324124962006505075L;

@Column(name = "target_user_profile_id")
private Long targetUserProfileID = null;

@Column(name = "user_profile_id")
private Long userProfileID = null;

...

}

@Entity(name = "LinkedUserProfile")
@Table(name = "LinkedUserProfile")
public class LinkedUserProfileBean extends AbstractDomainEntity<LinkedUserProfileKey> {

@Column
@Temporal(TemporalType.TIMESTAMP)
@NotNull
private OffsetDateTime createdDate = null;

@EmbeddedId
private LinkedUserProfileKey id = null;

@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "target_user_profile_id", referencedColumnName = "id")
@MapsId("targetUserProfileID")
@NotNull
private UserProfileBean targetUserProfile = null;

@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "user_profile_id", referencedColumnName = "id")
@MapsId("userProfileID")
@NotNull
private UserProfileBean userProfile = null;

...

}
I haven't found any good documentation that explains how I would model my class using Swift and Fluent, though. Can anyone give an example of how to model this class? The primary key should be a composite primary key, consisting of user_profile_id and target_user_profile_id. Thoughts?

chrome shell
frosty trellis
#

So, is there a way to declare a @Sibling property in another entity for this type of setup? I've got the mapping working properly. What if I wanted to create a relation in another entity to my LinkedUserProfile? Is that possible?