如何使用复合键映射多对多

2024-05-09

我有以下表格

Trainingplan
    TrainingplanID int(11) AI PK
    Trainer int(11)
    Client int(11)
    validFrom date
    validTo date
    type int(11)

TrainingplanExercises
    trainingplan int(11) PK
    exercise int(11) PK
    parameter int(11) PK
    value varchar(45)

不,我在将它们与 Hibernate 连接时遇到问题。我做了以下事情: 包装豆;

@Entity
@Table(name = "Trainingplan")
public class Training {

    private IntegerProperty id;
    private ObjectProperty<Person> client;
    private ObjectProperty<Person> trainer;
    private ObjectProperty<Date> validFrom;
    private ObjectProperty<Date> validTo;
    private ObjectProperty<TrainingplanType> type;
    private List<TrainingplanExercise> exercises;

    public Training(int id, Person client, Person trainer, Date validFrom, Date validTo, TrainingplanType type) {
        this.id = new SimpleIntegerProperty(id);
        this.client = new SimpleObjectProperty<>(client);
        this.trainer = new SimpleObjectProperty<>(trainer);
        this.validFrom = new SimpleObjectProperty<>(validFrom);
        this.validTo = new SimpleObjectProperty<>(validTo);
        this.type = new SimpleObjectProperty<>(type);
        exercises = FXCollections.observableArrayList();
    }

    public Training(Person client, Person trainer, Date validFrom, Date validTo, TrainingplanType type){
        this(0, client, trainer, validFrom, validTo, type);
    }

    public Training(){
        this(0, null,null,null,null, null);
    }

    @OneToOne
    @JoinColumn(name = "client")
    public Person getClient() {
        return client.get();
    }

    public ObjectProperty<Person> clientProperty() {
        return client;
    }

    public void setClient(Person client) {
        this.client.set(client);
    }

    @OneToOne
    @JoinColumn(name = "trainer")
    public Person getTrainer() {
        return trainer.get();
    }

    public ObjectProperty<Person> trainerProperty() {
        return trainer;
    }

    public void setTrainer(Person trainer) {
        this.trainer.set(trainer);
    }

    @Column
    public Date getValidFrom() {
        return validFrom.get();
    }

    public ObjectProperty<Date> validFromProperty() {
        return validFrom;
    }

    public void setValidFrom(Date validFrom) {
        this.validFrom.set(validFrom);
    }

    @Column
    public Date getValidTo() {
        return validTo.get();
    }

    public ObjectProperty<Date> validTillProperty() {
        return validTo;
    }

    public void setValidTo(Date validTill) {
        this.validTo.set(validTill);
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "TrainingplanID")
    public int getId() {
        return id.get();
    }

    public IntegerProperty idProperty() {
        return id;
    }

    public void setId(int id) {
        this.id.set(id);
    }

    @OneToOne
    @JoinColumn(name = "type")
    public TrainingplanType getType() {
        return type.get();
    }

    public ObjectProperty<TrainingplanType> typeProperty() {
        return type;
    }

    public void setType(TrainingplanType type) {
        this.type.set(type);
    }

    @ManyToMany()
    @JoinTable(name="TrainingplanExercises",
            joinColumns={@JoinColumn(name="trainingplan")},
            inverseJoinColumns={@JoinColumn(name="trainingplan"), @JoinColumn(name="exercise"), @JoinColumn(name="parameter")})
    public List<TrainingplanExercise> getExercises() {
        return exercises;
    }

    public void setExercises(List<TrainingplanExercise> exercises) {
        this.exercises = exercises;
    }

    @Override
    public String toString() {
        return "Training{" +
                "id=" + getId() +
                ", client=" + getClient() +
                ", trainer=" + getTrainer() +
                ", validFrom=" + getValidFrom() +
                ", validTill=" + getValidTo() +
                ", type=" + getType() +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Training training = (Training) o;

        return id != null ? id.equals(training.id) : training.id == null;

    }

    @Override
    public int hashCode() {
        return id != null ? id.hashCode() : 0;
    }
}

训练计划Exercise.java

@Entity
@Table(name = "TrainingplanExercises")
@IdClass(TrainingplanExerciseId.class)
public class TrainingplanExercise {

    private ObjectProperty<Exercise> exercise;
    private ObjectProperty<Training> training;
    private ObjectProperty<String> value;
    private ObjectProperty<Parameter> parameter;

    public TrainingplanExercise(Exercise exercise, Training training, String value, Parameter parameter){
        this.exercise = new SimpleObjectProperty<>(exercise);
        this.training = new SimpleObjectProperty<>(training);
        this.value = new SimpleObjectProperty<>(value);
        this.parameter = new SimpleObjectProperty<>(parameter);
    }

    public TrainingplanExercise(){
        this(null,null,null,null);
    }

    @Id
    @OneToOne
    @JoinColumn(name = "parameter")
    public Parameter getParameter() {
        return parameter.get();
    }

    public ObjectProperty<Parameter> parameterProperty() {
        return parameter;
    }

    public void setParameter(Parameter parameter) {
        this.parameter.set(parameter);
    }

    @Id
    @OneToOne
    @JoinColumn(name = "exercise")
    public Exercise getExercise() {
        return exercise.get();
    }

    public ObjectProperty<Exercise> exerciseProperty() {
        return exercise;
    }

    public void setExercise(Exercise exercise) {
        this.exercise.set(exercise);
    }

    @Id
    @OneToOne
    @JoinColumn(name = "trainingplan")
    public Training getTraining() {
        return training.get();
    }

    public ObjectProperty<Training> trainingProperty() {
        return training;
    }

    public void setTraining(Training training) {
        this.training.set(training);
    }

    @Column(name = "value")
    public String getValue(){
        return value.get();
    }

    public ObjectProperty<String> valueProperty() {
        return value;
    }

    public void setValue(String value) {
        this.value.set(value);
    }

    @Override
    public String toString() {
        return "TrainingplanExercise{" + "exercise=" + exercise + ", training=" + training + ", value=" + value + '}';
    }

}

 class TrainingplanExerciseId implements Serializable{
     protected ObjectProperty<Exercise> exercise;
     protected ObjectProperty<Training> training;
     protected ObjectProperty<Parameter> parameter;

     public TrainingplanExerciseId() {
         if(exercise == null)
             exercise = new SimpleObjectProperty<>(null);

         if(training == null)
             training = new SimpleObjectProperty<>(null);

         if(parameter == null)
             parameter = new SimpleObjectProperty<>(null);
     }

     public TrainingplanExerciseId(ObjectProperty<Exercise> exercise, ObjectProperty<Training> training, ObjectProperty<Parameter> parameter) {
         this.exercise = exercise;
         this.training = training;
         this.parameter = parameter;
     }

     @Override
     public boolean equals(Object o) {
         if (this == o) return true;
         if (o == null || getClass() != o.getClass()) return false;

         TrainingplanExerciseId that = (TrainingplanExerciseId) o;

         if (exercise != null ? !exercise.equals(that.exercise) : that.exercise != null) return false;
         if (training != null ? !training.equals(that.training) : that.training != null) return false;
         return parameter != null ? parameter.equals(that.parameter) : that.parameter == null;

     }

     @Override
     public int hashCode() {
         int result = exercise != null ? exercise.hashCode() : 0;
         result = 31 * result + (training != null ? training.hashCode() : 0);
         result = 31 * result + (parameter != null ? parameter.hashCode() : 0);
         return result;
     }

     public Exercise getExercise() {
         return exercise.get();
     }

     public ObjectProperty<Exercise> exerciseProperty() {
         return exercise;
     }

     public void setExercise(Exercise exercise) {
         this.exercise.set(exercise);
     }

     public Training getTraining() {
         return training.get();
     }

     public ObjectProperty<Training> trainingProperty() {
         return training;
     }

     public void setTraining(Training training) {
         this.training.set(training);
     }

     public Parameter getParameter() {
         return parameter.get();
     }

     public ObjectProperty<Parameter> parameterProperty() {
         return parameter;
     }

     public void setParameter(Parameter parameter) {
         this.parameter.set(parameter);
     }
 }

现在,当我想保存新的训练时,我收到此错误:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'TrainingplanID' in 'field list'

因为这个 SQL:

Hibernate: insert into TrainingplanExercises (TrainingplanID, trainingplan, exercise, parameter) values (?, ?, ?, ?)

我该如何解决? 如果我将 joinColumn 更改为“trainingplan”,我会收到错误消息,有两个相同的列。如果我从反向列中删除“trainingplan”,则会收到一条错误消息,其中缺少一个,因为外部约束需要 3 列

编辑: 尝试一下评论中的一些内容。我确实尝试过 OneToMany/ManyToOne:

@Id
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "trainingplan", nullable = false)
public Training getTraining() {
    return training.get();
}

@OneToMany(fetch = FetchType.EAGER, mappedBy = "training")
public List<TrainingplanExercise> getExercises() {
    return exercises;
}

如果我现在尝试将训练保存到数据库,它就会起作用。 假设我想从数据库中获取 Trainingplan,并添加新的 TrainingplanExercises。我会使用这段代码:

Exercise ex = (Exercise) db.getAll(Exercise.class).get(1);


Training t = (Training) db.getAll(Training.class).get(0);


TrainingplanExercise te = new TrainingplanExercise(ex, t, "asdf", ex.getParameters().get(0));
TrainingplanExercise te1 = new TrainingplanExercise(ex, t, "asdf", ex.getParameters().get(1));
TrainingplanExercise te2 = new TrainingplanExercise(ex, t, "asdf", ex.getParameters().get(2));
TrainingplanExercise te3 = new TrainingplanExercise(ex, t, "asdf", ex.getParameters().get(3));



t.getExercises().clear();
t.getExercises().add(te);
t.getExercises().add(te1);
t.getExercises().add(te2);
t.getExercises().add(te3);

db.updateObj(t);

我得到这个异常:

Exception in thread "main" org.hibernate.exception.LockTimeoutException: could not execute statement
    at org.hibernate.dialect.MySQLDialect$1.convert(MySQLDialect.java:447)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:211)
    at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:62)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3124)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3581)
    at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:104)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:465)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:351)
    at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)
    at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)
    at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1258)
    at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:425)
    at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:177)
    at db.Database.updateObj(Database.java:100)
    at db.Database.main(Database.java:171)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3835)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3771)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2535)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1911)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2145)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2081)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2066)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
    ... 19 more

好吧,看一下。你遇到的是一个设计问题,而不是一个普遍的问题。首先,据我了解,你想要制作一套独特的TrainingplanExercise's。为此,你有这个Entity:

@Entity
public class TrainingplanExercise implements Serializable {
    @EmbeddedId private TrainingplanExerciseId trainingplanExerciseId;

    public TrainingplanExercise() {}        
    public TrainingplanExercise(TrainingplanExerciseId trainingplanExerciseId) {
        this.trainingplanExerciseId = trainingplanExerciseId;
    }
    ... other fields ...   
}

以上的区别Entity和你原来的Entity是我已经做了ID an EmbeddableId。为了确保只将独特的练习放入TrainingplanExercise's, 你有一个compositeKey被定义为一个单独的类:

@Embeddable
public class TrainingplanExerciseId implements Serializable {
    private String exercise;
    private String parameter;

    public TrainingplanExerciseId() {}
    public TrainingplanExerciseId(String exercise, String parameter) {
        this.exercise = exercise;
        this.parameter = parameter;
    }

    ... getters, setters, hashCode, and equals
}

在这里,我已经上课了Embeddable以便它可以用作ID。你试图声明的方式compositeKey没有任何意义;您试图声明中的每个单独字段TrainingplanExercise Entity as an ID,但你只能拥有一个ID.

这有什么不同model那是TrainingplanExerciseId compositeKey不包括对a的引用TrainingPlan。如果您想获取以下列表TrainingPlan's使用任何特定的TrainingplanExercise,那么你需要一个双向而不是单向关系 https://howtoprogramwithjava.com/hibernate-manytomany-unidirectional-bidirectional/,但那是另一个问题了。否则,我不知道你为什么要参考TrainingPlan from a TrainingplanExercise。此外,您还引用了TrainingPlan进入TrainingplanExerciseId compositeKey,这需要TrainingPlan被序列化,这实际上不能作为唯一的 ID。

现在您可以将单独的练习放入表中:

public TrainingplanExercise createExercise(String exercise, String parameter) {
    TrainingplanExercise trainingplanExercise = new TrainingplanExercise(new TrainingplanExerciseId(exercise, parameter));
    em.persist( trainingplanExercise );
    return trainingplanExercise;
}

之后,您想要拥有任意数量的TrainingPlan's就是利用可能的TrainingplanExercise's,你用这个做的Entity:

@Entity
public class TrainingPlan implements Serializable {
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;

    @ManyToMany(fetch=FetchType.EAGER)
    private List<TrainingplanExercise> trainingplanExercises = new ArrayList<TrainingplanExercise>();

    ... getters, setters, 
}

你有一个ManyToMany关系因为一个TrainingPlan指的是许多TrainingplanExercise's and a TrainingplanExercise被很多人使用TrainingPlan's。除此之外你不需要任何特殊的注释ManyToMany, the JPA提供商将创建一个link table,将每个密钥Entity排成一行,像这样:

create table TrainingPlan_TrainingplanExercise (
    TrainingPlan_id bigint not null,
    trainingplanExercises_exercise varchar(255) not null,
    trainingplanExercises_parameter varchar(255) not null
);

如果您将其声明为OneToMany关系,那么JPA提供商将额外添加constraint on the link table确保一个TrainingplanExercise不能链接到多个TrainingPlan,所以你不想要这样。仅作为示例,这就是约束的样子。

alter table TrainingPlan_TrainingplanExercise 
    add constraint UK_t0ku26ydvjkrme5ycrnlechgi  unique (trainingplanExercises_exercise, trainingplanExercises_parameter);

创建和更新TrainingPlans很简单:

public TrainingPlan createTrainingPlan() {
    TrainingPlan trainingPlan = new TrainingPlan();
    em.persist(trainingPlan);
    return trainingPlan;
}
public TrainingPlan updateTrainingPlan(TrainingPlan trainingPlan) {
    return em.merge(trainingPlan);
}

现在,您可以创建TrainingplanExercises and TrainingPlans,并将练习添加到训练计划中并更新。

TrainingplanExercise squats20 = trainingService.createExercise("Squats", "20");
TrainingplanExercise lifts10 = trainingService.createExercise("Lifts", "10");
TrainingplanExercise crunches50 = trainingService.createExercise("Crunches", "50");

TrainingPlan trainingPlan = trainingService.createTrainingPlan();
trainingPlan.getTrainingplanExercises().add( squats20 );
trainingPlan.getTrainingplanExercises().add( lifts10 );
trainingService.updateTrainingPlan(trainingPlan);

trainingPlan = trainingService.createTrainingPlan();
trainingPlan.getTrainingplanExercises().add( lifts10 );
trainingPlan.getTrainingplanExercises().add( crunches50 );
trainingService.updateTrainingPlan(trainingPlan);

另请注意,您的应用程序面临的挑战是确保只有唯一的TrainingplanExercises由用户创建。如果一个TrainingplanExercise有重复的exercise and parameter试图创建你会得到一个Unique index or primary key violation异常,事务将被回滚。

编辑:用于阅读TrainingPlans,可以使用这样的东西:

public List<TrainingPlan> listTrainingPlans() {
    CriteriaQuery<TrainingPlan> criteria = em.getCriteriaBuilder().createQuery(TrainingPlan.class);
    criteria.select(criteria.from(TrainingPlan.class));
    List<TrainingPlan> trainingPlans = em.createQuery(criteria).getResultList();
    return trainingPlans;
}

请注意,自从List<TrainingplanExercise> trainingplanExercises被设定为FetchType.EAGER这个特定的查询将拉入整个数据库。FetchType.EAGER阅读单个内容可能不是问题TrainingPlan,但如果你只想要一个列表TrainingPlan's如果没有获得所有详细信息,那么您需要弄清楚如何FetchType.LAZY应予以实施。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用复合键映射多对多 的相关文章

随机推荐

  • java.sql.SQLException:在结果集开始之前[重复]

    这个问题在这里已经有答案了 我已尝试使用以下代码来检索存储在数据库中的图像 我创建了一个名为image db包含一个名为的表image details 该表有两个字段 id and image path两者都是类型mediumblob 我在
  • env 配置文件中未初始化的常量 ActiveSupport::EventedFileUpdateChecker

    我是 Ruby on Rails 的新手 运行 捆绑 命令进行更新 安装后 当我尝试执行以下操作时rails s or rails g mongoid config控制台返回以下消息开头 home myUser proyect config
  • Android 视图展开动画

    我正在尝试编辑这些来源 https github com gabrielemariotti androiddev tree master AnimationTest创建一个适用于我所有视图的简单函数 Override public void
  • xdotool 类型需要很长时间并导致整个桌面冻结

    我一直在使用xdotool type过去只能在快捷方式上输入耸肩xdotool type 这可行 但总是需要相当长的时间 并导致整个桌面冻结 完全冻结 而不仅仅是输入 几秒钟 不过并没有太打扰我 现在我需要一种方法来从文件中读取内容 对其进
  • Android ACTION_DATE_CHANGED 广播

    我有 Nexus S 当我在手机上手动更改日期时 ACTION DATE CHANGED 并不总是被广播 如果我将日期从 2014 年 2 月 13 日更改为 2014 年 2 月 14 日 我还没有获得 ACTION DATE CHANG
  • 禁用页面的浏览器打印选项(页眉、页脚、边距)?

    我在 SO 和其他几个网站上看到过以几种不同的方式提出这个问题 但大多数都太具体或过时了 我希望有人能在这里提供明确的答案 而不是迎合猜测 当有人在浏览器中打印时 有没有办法使用 CSS 或 javascript 更改默认打印机设置 当然
  • 熊猫滚动意味着更新

    考虑数据框 df pd DataFrame a None None None None 1 2 1 0 1 b 5 4 6 7 None None None None None gt gt a b 0 NaN 5 0 1 NaN 4 0 2
  • glBlitFramebuffer 渲染缓冲区和渲染全屏纹理哪个更快?

    哪个更快更高效 使用 OpenGL 纹理作为 CUDA 表面并在四边形上渲染 新样式 使用渲染缓冲区作为 CUDA 表面并使用 glBlitFramebuffer 进行渲染 None
  • 设置字节中的特定位

    我正在尝试设置 Java 字节变量中的位 它确实提供了适当的方法 例如 setBit i 有谁知道我如何才能实现这一点 我可以按位迭代给定的字节 if my byte 1 lt lt i 0 但是我不能将此位置设置为 1 或 0 可以吗 使
  • 在composer.json中运行命令行命令

    我正在尝试编写一个composer json 文件 该文件将连续运行多个命令行命令 作为一个示例 如下所示 scripts test createDir createDir mkdir testing 当我在终端中运行作曲家文件时使用com
  • 使用 javascript 选择框架上下文

    有没有一种方法可以使用 Javascript 以编程方式选择框架上下文 假设当前网页中有两个不同的框架 我需要将 hello 附加到第二个框架 问题是第二个框架的域与当前网页不同 使用 Chrome 开发者工具 我可以简单地选择第二个框架上
  • 类似的 PHP 表单代码:如果 $_REQUEST 为空,第一个抛出错误,第二个则不抛出错误

    我是 PHP 新手 所以这可能是一个简单的答案 希望我能正确地按照 SO 标准格式化它 对于该网站来说仍然是新的 我正在通过 SitePoint 编写两组非常相似的代码 提交表单数据并使用 htmlspecialchars 来阻止 XSS
  • pytest 在导入时找不到模块,但代码运行良好

    目标是为使用 Cython 的 Python3 项目使用 pytest 单元测试框架 这不是即插即用的事情 因为默认情况下 pytest 无法导入 Cython 模块 也就是说 从 Cython pyx 模块导入时出现以下错误 在我的例子中
  • C++/CLI 在运行时显式加载托管 DLL(相当于非托管的 LoadLibrary)

    问题一 有没有办法在 C CLI 中在运行时而不是在编译时显式加载库 目前我在编译时使用 NET 添加引用 我想显式加载托管 dll NET 中是否有 LoadLibrary 的等效项 Update 感谢兰多夫 Assembly LoadF
  • Angularjs 中字母数字的正则表达式

    我想要 angularJS 中字母数字字符的正则表达式 我尝试了一些正则表达式 例如 d a z 但它们允许我仅输入数字和字母 但我想要一个不允许我输入它们的正则表达式 例子 121232 abchfe abd 42232 5 是一些例子i
  • perl imap 将邮件移至垃圾箱 (Mail::IMAPClient)

    我需要将所有未见的邮件移至垃圾箱 然后从收件箱中删除 my inbox imap gt select Inbox my mails imap gt unseen foreach my msgid mails imap gt set flag
  • Spring 将 URL 映射到控制器和视图

    我在 Netbeans 8 0 2 中有标准的 Spring 4 x 文件 我添加了一个控制器 RegisterController java in the controllers 包裹 我还添加了一个模型 一个User 以及有关用户的一些
  • Django:使用 python-magic 在模型中进行文件字段验证

    我有一个包含文件字段的模型 我想将其限制为 pdf 文件 我在模型中编写了干净的方法 因为我还想检查管理和 shell 级别模型的创建 但它不适用于模型清理方法 然而 形式清洁方法正在发挥作用 class mymodel models Mo
  • 同一参数有两个不同的名称有什么意义?

    func mapEachElement inArray arr Int withFunc aFunc Int 为什么会有 inArray 然后 arr 有什么意义 对于 withFunc 和 aFunc 也是如此 它使代码变得更加复杂并且阅
  • 如何使用复合键映射多对多

    我有以下表格 Trainingplan TrainingplanID int 11 AI PK Trainer int 11 Client int 11 validFrom date validTo date type int 11 Tra