deimos_ has quit [Remote host closed the connection]
Andriamanitra has joined #crystal-lang
<FromGitter>
<ilourt> Hi all,
<FromGitter>
<ilourt> I'm using Granite as an orm. I want to have a base model class (with columns) and then use it by inheritance in other models. The problem is that I have the following error linked with granite: `Error: class variable '@@validators' of App::Models::BaseModel is already defined as Array(NamedTuple(field: String, message: String, block: Proc(App::Models::Zone, Bool))) in App::Models::MyModel`
<FromGitter>
<ilourt> Someon have any idea how I could achieve inheritance with Granite ORM?
<FromGitter>
<grkek> How does one pass a function as an argument?
<FromGitter>
<naqvis> @grkek use `Proc`
<FromGitter>
<grkek> Understandable
<FromGitter>
<naqvis> or you can use block
<FromGitter>
<grkek> Do you know any block magic?
<FromGitter>
<naqvis> in what sense?
<FromGitter>
<naqvis> btw you can pass methods as block as well
<FromGitter>
<grkek> Cool tricks with blocks
<FromGitter>
<grkek> Hm how do I do that?
<FromGitter>
<naqvis> just prepend `&`
<FromGitter>
<grkek> Why can't setter methods use blocks?
<FromGitter>
<grkek> Can you show me an example of passing a function in a block?
<FromGitter>
<j8r> there is also `my_func &->other_func`
<FromGitter>
<Dan-Do> > Can you show me an example of passing a function in a block? ⏎ ⏎ macro `content_for` in kemal uses block
<FromGitter>
<naqvis> @ilourt don't know Granite, but a quick look at their code base revealed that, `Granite::Base` isn't designed to be used in your use-case. Both Base and `Validators` have defined macro `inherited` hook, which got executed during compilation time, and causes the code inside those macros to get added to classes.
<FromGitter>
<naqvis> For your use-case you might try to composition approach other than inheritance heriarchy
<FromGitter>
<ilourt> @naqvis thanks for your answer. It is very annoying that we can not use the base of the OOP. The problem is that there is no real good orm in crystal :(
<FromGitter>
<Dan-Do> what db are you using?
<FromGitter>
<ilourt> postgres
<FromGitter>
<Dan-Do> fair enough, I am using nosql, which return JSON, so easier :)
f1reflyylmao is now known as f1refly
<FromGitter>
<ilourt> ;) In this case I have no choice but to use sql