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

时间:2013-08-22 15:14:40

标签: greendao

下面是我的模式生成代码,模型类(Survey& Question)中没有自动生成两个变量(storeIdForSurvey& questionIdForAnswer),尽管它们出现在自动生成的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");



    }

1 个答案:

答案 0 :(得分:2)

请仔细阅读文档:

public ToOne addToOne(Entity target, Property fkProperty)
  

使用给定的给定对象向给定目标实体添加一对一关系   外键属性(属于该实体)。

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

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

但是下一个语句不正确,因为Property storeIdForSurvey不是Entity商店的成员:

store.addToOne(survey, storeIdForSurvey);

请尝试使用此声明:

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