Sugar ORM for Android cannot find my column name

Well, I'm trying to select all objects where entitie_id = *some id*

I do this with this rule:

 List<NodeSugar> nodesugars = NodeSugar.find(NodeSugar.class, "entitie_id = ? ", String.valueOf(nodeid)); 

I know that I need to return some results, and I get an error message. this error:

 E/SQLiteLog๏น• (1) no such column: entitie_id 

I know that a column exists because I can set it in another part of the code.

Where am I going wrong?

+6
source share
2 answers

You should be able to request a "entitieid".

Sugar ORM does some conversion when it creates columns in tables. Here is an example:

 String firstName; //creates column first_name int entitie_id; //creates column entitieid 

The documentation indicates only the conversion from the camel cabinet for underlining. I had to understand another.

+29
source

You can use NamingHelper.toSQLNameDefault () to wrap column names when building queries. Try:

 List<NodeSugar> nodesugars = NodeSugar.find(NodeSugar.class, NamingHelper.toSQLNameDefault("entitie_id") + " = ? ", String.valueOf(nodeid)); 

NamingHelper is used in the Sugar ORM library to create table and column names:

https://github.com/satyan/sugar/blob/master/library/src/main/java/com/orm/helper/NamingHelper.java

+7
source

Source: https://habr.com/ru/post/985175/


All Articles