我想知道如何选择外键引用的字段。我在文档中找不到它。
例如,如果我有一个<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<AnchorPane id="AnchorPane" prefHeight="300.0" prefWidth="639.0"
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="javafxapp.controller.FXMLCatalogoController">
<children>
<SplitPane dividerPositions="0.5100334448160535" layoutX="-3.0"
prefHeight="300.0" prefWidth="647.0" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="-3.0" AnchorPane.rightAnchor="-5.0"
AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="298.0"
prefWidth="322.0">
<children>
<TableView fx:id="tabelaContato" editable="true"
layoutX="-14.0" prefHeight="298.0" prefWidth="336.0"
tableMenuButtonVisible="true" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="-14.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0">
<columns>
<TableColumn fx:id="columnNome" prefWidth="75.0"
text="Nome" />
<TableColumn fx:id="columnSobrenome" prefWidth="75.0"
text="Sobrenome" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"
/>
</columnResizePolicy>
</TableView>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="298.0"
prefWidth="251.0">
<children>
<Label layoutX="24.0" layoutY="-7.0" prefHeight="57.0" prefWidth="162.0" text="Person Details" AnchorPane.leftAnchor="10.0">
<font>
<Font size="18.0" />
</font>
</Label>
<GridPane layoutX="30.0" layoutY="48.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="50.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="25.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="25.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="25.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="25.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="25.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="25.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Nome:" />
<Label text="Sobrenome:" GridPane.rowIndex="1" />
<Label text="Cidade:" GridPane.rowIndex="2" />
<Label text="Estado:" GridPane.rowIndex="3" />
<Label text="CEP:" GridPane.rowIndex="4" />
<Label text="Data Nasc.:" GridPane.rowIndex="5" />
<Label fx:id="labelNome" GridPane.columnIndex="1" />
<Label fx:id="labelSobrenome" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label fx:id="labelCidade" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label fx:id="labelEstado" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label fx:id="labelCep" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Label fx:id="labelDataNasc" GridPane.columnIndex="1" GridPane.rowIndex="5" />
</children>
</GridPane>
<Button layoutX="22.0" layoutY="259.0" mnemonicParsing="false" text="Novo" />
<Button layoutX="133.0" layoutY="259.0" mnemonicParsing="false" text="Editar" />
<Button layoutX="225.0" layoutY="259.0" mnemonicParsing="false" text="Remover" />
</children></AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
表和一个Product
表。 ProductTag
hasMany Product
。然后我的ProductTags
表将通过以下内容获得ProductTag
表的外键:
Product
我的{ // Product
...
"relations": {
"productTags": {
"type": "hasMany",
"model": "ProductTag",
"foreignKey": ""
}
}
}
表格的字段为Product
- 我想将其设为ID ,id
- unique , sku
等等......
然后该关系将创建引用price
的外键。如何将其引用到Product.id
呢?
谢谢!
答案 0 :(得分:1)
您的产品有许多产品标签,因此在您的产品表中您有很多关系但在ProductTagTable中您拥有belongsTo关系,因为productTag属于ProductTable。
为了更好的选择, 您可以使用 lb model 命令询问您希望如何建立关系以及您希望为foreignKey指定哪个名称。
谢谢。
答案 1 :(得分:1)
this.dataSource.filterPredicate = (data, filter) =>
(data.name.indexOf(filter) !== -1 ||
data.id.indexOf(filter) !== -1 );
}
目标模型Order有一个属性 customerId,作为外来的 密钥引用声明模型(客户)主键ID 。