greenDao生成器在自动生成的类中不生成某些变量

  • 本文关键字:变量 自动生成 greenDao greendao
  • 更新时间 :
  • 英文 :


下面是我的模式生成代码,两个变量(storeIdForSurvey和questionIdForAnswer)没有在模型类(Survey和Question)中自动生成,尽管它们存在于自动生成的dao类(SurveyDao和QuestionDao)中。

域的面向对象描述为:用户有商店,商店有调查,调查有FollowupItems,调查有类别,类别有问题,问题有历史,问题有答案。

private static void addUser(Schema schema) {
    //User
    Entity user = schema.addEntity("User");
    user.addIdProperty();
    user.addStringProperty("districtId");
    user.addStringProperty("employeeId");
    user.addStringProperty("name");
    user.addStringProperty("sessionToken");
    user.addStringProperty("userId");

    //Store
    Entity store = schema.addEntity("Store");
    // foreign key
    Property userIdForStore = store.addLongProperty("userIdForStore").getProperty();
    store.addToOne(user, userIdForStore);
    user.addToMany(store, userIdForStore);

    store.addIdProperty();
    store.addStringProperty("storeId");
    store.addStringProperty("address");
    store.addStringProperty("city");
    store.addStringProperty("storeName");
    store.addStringProperty("state");
    store.addStringProperty("zip");
    store.addStringProperty("storeManagerName");
    store.addBooleanProperty("isSurveyHistoryAvailable");      


    //Survey
    Entity survey = schema.addEntity("Survey");
    //foreign key
    Property storeIdForSurvey = survey.addLongProperty("storeIdForSurvey").getProperty();
    survey.addToOne(store, storeIdForSurvey); // one store can have one survey at a time
    store.addToOne(survey, storeIdForSurvey);

    survey.addIdProperty();
    survey.addStringProperty("surveyId");
    survey.addStringProperty("dmSignImagePath");
    survey.addStringProperty("dmSignImageName");
    survey.addStringProperty("smSignImagePath");
    survey.addStringProperty("smSignImageName");
    survey.addStringProperty("startlatitude");
    survey.addStringProperty("startlongitude");
    survey.addStringProperty("submitLatitude");
    survey.addStringProperty("submitLongitude");
    survey.addStringProperty("acknowledgedBy");
    survey.addStringProperty("deliveredBy");
    survey.addStringProperty("name");
    survey.addStringProperty("createdBy");
    survey.addStringProperty("description");
    survey.addStringProperty("storeId");
    survey.addStringProperty("districtManager");

    survey.addDateProperty("startDate");
    survey.addDateProperty("submitDate");
    survey.addDateProperty("syncDate");
    survey.addDateProperty("createdDate");
    survey.addDateProperty("actionItemAssignDate");
    survey.addDateProperty("actionItemDueDate");
    survey.addDoubleProperty("score");


    //FolloupItems
    Entity followupItem = schema.addEntity("FollowupItem");

    //foreign key
    Property surveyIdForFollowupItem = followupItem.addLongProperty("surveyIdForFollowupItem").getProperty(); 
    followupItem.addToOne(survey, surveyIdForFollowupItem);
    survey.addToMany(followupItem, surveyIdForFollowupItem);

    followupItem.addIdProperty();
    followupItem.addStringProperty("assignedTo");
    followupItem.addStringProperty("comment");
    followupItem.addStringProperty("photoName");
    followupItem.addStringProperty("photoURL");
    followupItem.addDateProperty("assignedDate");
    followupItem.addDateProperty("dueDate");
    followupItem.addDateProperty("expeireDate");


    //Category

    Entity category = schema.addEntity("Category");

    //foreign key
    Property surveyIdForCategory = category.addLongProperty("surveyIdForCategory").getProperty();
    category.addToOne(survey, surveyIdForCategory);
    survey.addToMany(category, surveyIdForCategory);

    category.addIdProperty();
    category.addStringProperty("categoryId");
    category.addStringProperty("name");
    category.addStringProperty("weight");
    category.addStringProperty("surveyId");
    category.addDoubleProperty("totalScore");
    category.addIntProperty("sortOrder");
    category.addBooleanProperty("completionStatus");
    category.addBooleanProperty("hasActionItem");

    //Question
        Entity question = schema.addEntity("Question");

        //foreign key
        Property categoryIdForQuestion = question.addLongProperty("categoryIdForQuestion").getProperty();
        question.addToOne(category, categoryIdForQuestion);
        category.addToMany(question, categoryIdForQuestion);

        question.addIdProperty();
        question.addStringProperty("questionId");
        question.addDateProperty("startDate");
        question.addDateProperty("endDate");
        question.addStringProperty("statement");
        question.addStringProperty("type");
        question.addStringProperty("weight");
        question.addStringProperty("surveyCategoryName");
        question.addIntProperty("displayOrder");
        question.addBooleanProperty("naFlag");
        question.addBooleanProperty("isRequired");

      //Question History
    Entity questionHistory = schema.addEntity("questionHistory");

    //foreign key
    Property questionIdForQuestionHistory =  questionHistory.addLongProperty("questionIdForQuestionHistory").getProperty();
    questionHistory.addToOne(store, questionIdForQuestionHistory);
    question.addToMany(questionHistory, questionIdForQuestionHistory);

    questionHistory.addIdProperty();
    questionHistory.addStringProperty("questionId");
    questionHistory.addStringProperty("secondLastHistory");
    questionHistory.addStringProperty("lastHistory");


        //Answer
        Entity answer = schema.addEntity("Answer");

        //foreign key
        Property questionIdForAnswer = answer.addLongProperty("questionIdForAnswer").getProperty();
        question.addToOne(answer, questionIdForAnswer);
        answer.addToOne(question, questionIdForAnswer);

        answer.addIdProperty();
        answer.addStringProperty("projectType");
        answer.addStringProperty("assignedTo");
        answer.addStringProperty("comment");
        answer.addStringProperty("photoUrl");
        answer.addStringProperty("photoNmae");
        answer.addStringProperty("selectedOption");
        answer.addDateProperty("assignedDate");
        answer.addDateProperty("dueDate");
        answer.addDateProperty("expireDate");
        answer.addDoubleProperty("score");

    }

请仔细阅读文档:

public ToOne addToOne(Entity target, Property fkProperty)

使用给定的外键属性(属于此实体)。

这意味着以下陈述是正确的:

Property storeIdForSurvey = survey.addLongProperty("storeIdForSurvey").getProperty();
survey.addToOne(store, storeIdForSurvey); 

但是下一条语句不正确,因为Property storeIdForSurvey不是实体存储的成员:

store.addToOne(survey, storeIdForSurvey);

请尝试使用以下语句:

store.addToOneWithoutProperty("Survey", survey, "storeIdForSurvey");

相关内容

  • 没有找到相关文章

最新更新