How can I query a field which is null? I get a a sql error
filter=[where][category_id][eq][null] results in
SELECT WHERE category_id'null' ORDER BY id
using latest version of loopback and loopback-connector-mysql
You can use filter like
/model?filter[where][category_id][eq]=null
As you see in loopback
/medias?filter[where][keywords][inq]=foo&filter[where][keywords][inq]=bar
reference link : here
Related
I have the following QuerySet:
MyModel.objects
.order_by("foreign_key_id")
.distinct("foreign_key_id")
.in_bulk(field_name="foreign_key_id")
foreign_key_id is not unique on MyModel but given the use of distinct should be unique within the QuerySet.
However when this runs the following error is raised:
"ValueError: in_bulk()'s field_name must be a unique field but 'foreign_key_id' isn't."
According to the Django docs on in_bulk here it should be possible to use in_bulk with distinct in this way. The ability was added to Django in response to this issue ticket here.
What do I need to change here to make this work?
I'm using Django3.1 with Postgres11.
As the documentation of in_bulk(…) says:
(…)
Changed in Django 3.2:
Using a distinct field was allowed.
Since you use django-3.1, this will thus not work, you will thus have to upgrade your program to django-3.2.
I am trying to get data from my data source using loopback 4. It is working fine if the table name is simple and does not contain any special character.
But if there is a table with some special character like Underscore it does not allow me to create a model for that and I am not able to access the data from that table.
I have a table named "my_data" that contains column:- id,first_name,last_name.
But when I use the command lb4 model and pass the model name as my_data it converts it to my-data. and later on, when I call the API it throws an error by saying that relation publi.mydata does not exist.
WARNING: relational database doesn't support {strict: false} mode. {strict: true} mode will be set for model MyData instead.
Unhandled error in GET /my_data?filter=%7B%0A%20%20%22fields%22%3A%20%7B%0A%20%20%20%20%22id%22%3A%20true%2C%0A%20%20%20%20%first_name%22%3A%20true%2C%0A%20%20%20%20%22additionalProp1%22%3A%20%7B%7D%0A%20%20%7D%0A%7D: 500 error: relation "public.mydata" does not exist
at Connection.parseE (/Users/apple/others/loopback4/hello/node_modules/pg/lib/connection.js:614:13)
at Connection.parseMessage (/Users/apple/others/loopback4/hello/node_modules/pg/lib/connection.js:413:19)
at Socket.<anonymous> (/Users/apple/others/loopback4/hello/node_modules/pg/lib/connection.js:129:22)
at Socket.emit (events.js:315:20)
at addChunk (_stream_readable.js:297:12)
at readableAddChunk (_stream_readable.js:273:9)
at Socket.Readable.push (_stream_readable.js:214:10)
at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
Is ther any way to get data from table named like this? If anyone know how to do this please let me know.
Use settings.table in the #model decorator:
#model({
settings: {
table: 'my_data',
},
})
Further reading
https://loopback.io/doc/en/lb4/Model.html#data-mapping-properties
I use mongodb and c++ driver for it and
when I update some collection of documents with fields entid, div, name, fld2 using this code:
connection.update("mydb.mycol", Query(bob().append("entid",1).obj()), bob().append("div", 5).obj());
updating has been done successfully, but updated document has not entid, name and fld2 fields. How can I update document without missing fields I do not need to update?
You need the $set modifier. I don't know anything about the C++ driver but the JS syntax is:
db.mydb.update({"entid" : 1}, {"$set" : {"div" : 5}})
I hope you can transform this to C++ code ;)
I am having a weird problem with my mysql database and django.
I created an app with a model imported from an existing database with inspectdb. It was working fine until yesterday I removed the django automatically created tables (django_, auth_, site_*). I did that because it was preventing my model to validate when I added my app in the installed apps.
Now today I tried inserting a new record in my database and I get the following error :
Django Version: 1.3
Exception Type: IntegrityError
Exception Value: (1048, "Column 'asset_id' cannot be null")
The field is a primary key and it's supposed to be auto_increment so I don't give a value to it when I create a new record.
Can someone point me what's going on here ?
EDIT : I partly figured out the problem : somehow all my auto_increment proprities were removed from my database. How did that happen ?
Check your generated models, and ensure that the "auto_increment" columns correspond with fields marked with the primary_key=True option.
May be you need to save your object model, before obtain id property.
I am using solrj as client for indexing documents on the solr server.
I am having problem while deleting the indexes by 'id' from the solr server.
I am using following code to delete the indexes:
server.deleteById("id:20");
server.commit(true,true);
After this when i again search for the documents, the search result contains the above document also. Dont know what is going wrong with this code.
Please help me out with issue.
Thanks!
When you call deleteById, just use the id, without query syntax:
server.deleteById("20");
server.commit();
After you delete the document, commit the server and add the following lines.
After the server commit line.
UpdateRequest req = new UpdateRequest();
req.setAction( UpdateRequest.ACTION.COMMIT, false, false );
req.add( docs );
UpdateResponse rsp = req.process( server );
Use the method deleteByQuery() to delete the documents matching the query:
server.deleteByQuery("id:20");
server.commit();
So the deleteById will work only if you are forming your key using only one attribute. So, I had case where the id was a combination of multiple attributes like employeeId+deptId. But, my table had employeeId & deptId as separate columns as well with indexes created on it. So when I wanted to delete a record I had only the employeeId and not deptId. I used the curl command to delete where you can specify the column and its value and it will delete the entire record.
E.g.
curl http://localhost:8983/solr/update --data ':' -H 'Content-type:text/xml; charset=utf-8'