1

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

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

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");



    }
4

1 回答 1

2

请仔细阅读文档:

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");
于 2013-08-28T19:36:09.133 回答