-
Notifications
You must be signed in to change notification settings - Fork 683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validations #759
Comments
I played around with the code a bit more and I think I might be a bit closer in understanding my confusion. So like mentioned I have a longish background with Rails so I tend to compare functionality to it quite often (which might or might not make sense). It seems that there is a difference between |
@harjis , I agree that validation on DSL level will be a nice feature. About About We are going to release updated documentation later this year where this will be covered. |
My point about Hibernate: class PostController(private val postRepository) {
fun index() = postRepository.findAll()
} Rails: class PostController < ApplicationController
def index
@posts = Post.all
end
end Even though exposed DAO API looks very similar to Rails ActiveRercord one you can not use it the same way: data class PostView
class PostController {
fun index() = Post.all().map { PostView() } // Not OK because transaction has not been opened
} In order to make this to work I see 2 options. Either open a transaction in controller: class PostController {
fun index() = transaction { Post.all().map { PostView() } }
} Or create a repository class which opens the transaction: data class PostView
class PostRepository {
fun all() = transaction { Post.all() }
}
class PostController(private val postRepository) {
fun all() = postRepository.all().map { PostView() }
} Argument against opening transaction in controller is that in MVC controller should not know that much about the underlying persistence layer as that responsibility should be on the model. For me the repository one is a bit confusing as the exposed DAO API is so close Rails ActiveRercord one that I thought that should be the public API for the table but actually you can not use it the same way. My comments regarding |
Any update on this? Also supporting lifecycle hooks like "before save" etc. would be a way to hook in an existing validation library but those hooks don't exist either |
Hi,
I have been trying out Exposed for a while and I noticed that there is no built in support for validations either on DSL or DAO side. I suppose this is by design if Exposed is a lightweight SQL library. I can see the argument on not having validations in exposed. The reality however is that I have had the need for validations in every project I have been involved with.
If exposed is not going to have support for validations what do you think would be the best approach to deal with them on application level both on DSL and DAO style? One approach could be adding them to the repository:
DAO:
For a developer that comes from Ruby on Rails world this code looks a bit odd. My expectation was that Event class would be the public API to create new records in DB but at least if I want to add validations it looks like it can't be the public API. Also
all()
method is not transactional so is the design idea here indeed so that in both DSL and DAO styles a repository should be implemented which is transactional?Second question is also kind of related on validations. Is it so that there is no support for single table inheritance? In Rails what I could do is add validations but also relationships on the child models:
If there is no support in Exposed for this, ideas to implement this on application level are welcome too.
The text was updated successfully, but these errors were encountered: