-
Notifications
You must be signed in to change notification settings - Fork 87
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
[RFC] Remove validations #358
Comments
Any thoughts on this @robacarp @drujensen ? |
I’m ... still, I guess... not really warm to the idea of annotations as a mechanism for general development. More on topic, fixing the inheritance problem is certainly important, but I think it’ll need more than just Validations, it’ll probably require pulling out of depending on hooks entirely... both I think it’s important for Granite to ship with validations built in, but I agree that a substantial refactor is needed to get something which is scaleable in its implementation. |
so I am wondering if @Blacksmoke16 can do his magic and support both the |
We don't have any
I think ideally the interface that granite uses should be generic enough to allow for using whatever you want to use, be that I'm pretty sure But, maybe? The main question would be if you do like @[Column]
property email : String
@[Assert::Email]
@email : String where the ivar would have each annotation applied. However, IMO it would be easier to just tell people to add the annotation. @[Assert::Email]
@[Assert::NotBlank]
column email : String vs column email : String
assert Email, :email
assert NotBlank, :email It also would be less than ideal that granite would have a custom wrapper to a third party shard. |
I prefer something a little more rails like:
|
This is a referential integrity constraint and that is already available in mysql, postgres and sqlite as foreign key constraint. @drujensen I prefer something a little more rails like too and would prefer something that didn't rely on annotations. |
@damianham It looks like crystal is embracing annotations so not sure we have many options. The I was just hoping to put a little lipstick on the pig. |
It was more so meant to be an example of how the shard could be easily extended to support custom assertions. The point I was trying to show was related to amberframework/amber#698. I.e. it would allow you to share validations of when you go to save a model AND when validating input from a user; say when deserializing a JSON POST body, or when the form data is submitted. Currently Granite and Amber use two separate validations systems when it could all be tied into one.
Again, I'm not trying to say
|
@Blacksmoke16 Just to clarify, I wasn't calling your Option 2 is where we want to go. Just wondering if we can do it without forcing the user to use the annotation syntax. |
I know, all good :P...oink.
I'm sure it's possible, I just don't think it would be trivial. If someone wants to take a stab at it and gets something working id be happy to review it. |
See https://github.com/eliasjpr/schema as a possible approach that would not require annotations |
The current implementation of model validations is less than ideal. I.e. #123, #238. As I see it we have two options:
Based on the start of some of the conversation around amberframework/amber#698 a possible solution would be to use
https://github.com/Blacksmoke16/asserthttps://github.com/athena-framework/validator as an optional/recommended dependency. Granite itself could extendassert
in order to provide built in reusable assertions specific to data model validations, for example:Which would call the
.exists?
method (#343) on the given type and would only be valid if there is a user with the value ofauthor_id
; which would be useful when, for example, creating a post from form data or JSON.The other benefit would be enabling inheritance to be used. I would have to do some testing to see how it actually would work (I imagine there will be some work required to make MTI/STI possible), but would at least prevent compile errors until then.
The main con is of course it would break existing validations and would prevent using Amber with ORMs from using
assert
assertions, if the other ORM does not support applying annotations to their columns.Thoughts?
The text was updated successfully, but these errors were encountered: