-
-
Notifications
You must be signed in to change notification settings - Fork 195
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
Model instance should have toJSON method #21
Comments
Couple of things here. First Second when you call const record = yield Model.where('id', '=', 1).fetch()
console.log(record.first()) Also i am refactoring Lucid, so in coming future all these inconsistency issues will be resolved. |
Any reason why find() is a oh-so-special method that doesn't return a collection? And collection also uses a very old version of lodash, so I have to install a separate version... Collection seems less like something convenient, and more like a pain in the ass... |
Coz Collection means collection of multiple rows not collection of a single row. When you have multiple rows wrapped inside a collection, you can perform operations like |
where().first() returns just one row (not inside a list), but it's considered a collection (aka has a lodash wrapper, because that's really all that Collection is...) For consistency it should either return the row inside a list, or return just a Model instance like find, or make find also return a collection. |
If you are on |
Anytime when a single row is fetched intentionally, it will always be an instance otherwise a collection. |
Also, I notice that whenever a Collection is used, the wrapped values are not model instances, thus creating another inconsistency. |
Yes |
const feed = yield user.feed().fetch()
let index = 0
while( index < _.size(feed.value()) ) {
// as feed.value() will fetch collection not instance of model
// i need instance to update data in feed table
index++
} All good with Database query update, wanna do with db instance. Please guide. Thanks!! |
When getting a record via
Model.find()
, the returned object ignores the visible/hidden fields declared in the Model declaration. Also; the record itself is inside the attributes key & callingmodel.toJSON()
doesn't work.Getting the record via
model.where().fetch()
works fine. However; I can't access the first object of the returned array.When logging the record object in console, it looks like an array
[{ ... }]
but getting the first object of that arrayrecord[0]
does not work. It does work after calling themodel.toJSON()
method.find()
&where()
behave so differently?The text was updated successfully, but these errors were encountered: