Closed arthurfranca closed 4 years ago
Hey, sorry for the delay - holidays.
A collection is derived from Array
, so overwriting filter()
or push()
, ect... will conflict with existing methods. Currently there is no mechanism to check for this unintended overwrites.
What raw SQL queries do you need to write? Maybe scopes are better suited (internally it will create a static method, like you did).
Select ... from (select ...)
i.e. select from (subquery). I thought regular scope wouldn't work, as i need to return the result from this.raw()
, and i think scope always returns the query chain.
I've renamed to this.staticMethods.search
thx.
Ohh okay. I'll usually use VIEWS so solve this kind of problem. I'll try to implement this feature in V3.
Although undocumented, i've been using
this.staticMethods.methodName
at the definition scope to create a static method when using a funcion to define a model. It seems to be the right way when not using a class to define it, am i correct?. Mostly i use them for raw sql queries usingthis.raw(...).then({ rows } => ...}
or for setting constants likethis.staticMethods.TEST = 'test'
even though i'm not sure if it's the right place.Possibly a bug emerged when i did
this.staticMethods.filter = function (q) { ... }
and thenModel.create([{}, {}])
. It seems related to this line.I guess
filter
can't be used as a static method and i should just pick another name or was it an unexpected behavior?