Sugar ORM for Android cant find my column name

后端 未结 3 1734
-上瘾入骨i
-上瘾入骨i 2021-02-09 00:25

Well I\'m trying to select all entities where entitie_id = *some id*

I do this with this rule:

List nodesugars = NodeSugar.         


        
相关标签:
3条回答
  • 2021-02-09 00:43

    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 tables and column names:

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

    0 讨论(0)
  • 2021-02-09 00:45

    SugarORM currently uses toSQLName() method of the StringUtil class to generate names for columns For example in your case:

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

    The other and neat way to do it would be to use the Select class:

    List<NodeSugar> nodesugars = Select.from(NodeSugar.class).where(Condition.prop(StringUtil.toSQLName("entitie_id")).eq(nodeid)).list();
    

    https://satyan.github.io/sugar/query.html

    0 讨论(0)
  • 2021-02-09 00:55

    You should be able to query with "entitieid".

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

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

    The documentation only specifies the conversion from camel case to underscore separation. I had to figure the other one out.

    0 讨论(0)
提交回复
热议问题