You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, I've searched everywhere but couldn't find a forum / detailed guide on Exposed framework so I'm resorting to post an issue here.
How do you model a many-to-many relationship using the DAO (Entities) method? Take these models:
packageabcdimportorg.jetbrains.exposed.dao.*importorg.jetbrains.exposed.sql.*object Tags : IntIdTable(name = "tags") {
val name = text("name")
}
object Posts : IntIdTable(name = "posts") {
val uploadDate = datetime("upload_date")
}
object PostsTags : Table(name = "posts__tags") {
val post = reference("post", Posts).primaryKey(0)
val tag = reference("tag", Tags).primaryKey(1)
}
classTag(id:EntityID<Int>) : IntEntity(id) {
companionobject:IntEntityClass<Tag>(Tags)
var name by Tags.name
}
classPost(id:EntityID<Int>) : IntEntity(id) {
companionobject:IntEntityClass<Post>(Posts)
var uploadDate by Posts.uploadDate
val tags by Tag referrersOn PostsTags.tag // Obviously does not work. But how else?
}
How can I modify the Post entity so it has a tags property returning all tags associated to it through PostsTags? val tags by Tag referrersOn PostsTags.tag obviously doesn't work, and I couldn't find any similar alternative constructs.
In case such a scenario is not supported, how could one implement it? By looking on Referrers implementation I've got a general grasp on how to do it, but I'm struck at how to return a SizedIterable of tags from the results of a native SQL DSL query. Is there any mapping from SizedIterable<ResultRow> to SizedIterable<Entity>?
The text was updated successfully, but these errors were encountered:
Seems I was looking at it from the wrong direction. English is not my mother tongue, I had assumed via to meant something else altogether. Thank you very much.
I could send a pull request extending the current DAO samples to show via usage. Would it be desirable?
First, I've searched everywhere but couldn't find a forum / detailed guide on Exposed framework so I'm resorting to post an issue here.
How do you model a many-to-many relationship using the DAO (Entities) method? Take these models:
How can I modify the
Post
entity so it has atags
property returning all tags associated to it throughPostsTags
?val tags by Tag referrersOn PostsTags.tag
obviously doesn't work, and I couldn't find any similar alternative constructs.In case such a scenario is not supported, how could one implement it? By looking on
Referrers
implementation I've got a general grasp on how to do it, but I'm struck at how to return aSizedIterable
of tags from the results of a native SQL DSL query. Is there any mapping fromSizedIterable<ResultRow>
toSizedIterable<Entity>
?The text was updated successfully, but these errors were encountered: