Reactjs 如何将子数据数组以多通关系发送到api平台?
我有一个很好的实体,有3个多人关系 与ID字段链接的最终实体 我想将每个参数的每个值发送到API,并将其保存在数据库中 请参见下面的我的代码: 我的一个关联实体(模式和客户“准”相同): 具有链接结果的实体:Reactjs 如何将子数据数组以多通关系发送到api平台?,reactjs,api,symfony,Reactjs,Api,Symfony,我有一个很好的实体,有3个多人关系 与ID字段链接的最终实体 我想将每个参数的每个值发送到API,并将其保存在数据库中 请参见下面的我的代码: 我的一个关联实体(模式和客户“准”相同): 具有链接结果的实体: /** * @ApiResource( * normalizationContext={"groups"={"user:read"}}, * denormalizationContext={&q
/**
* @ApiResource(
* normalizationContext={"groups"={"user:read"}},
* denormalizationContext={"groups"={"user:write"}},
* collectionOperations={
* "get",
* "post"={"security"="is_granted('ROLE_ADMIN')"},
* },
* itemOperations={
* "get",
* "put"={"security"="is_granted('ROLE_ADMIN')"},
* "delete"={"security"="is_granted('ROLE_ADMIN')"},
* },
* )
* @ApiFilter(GroupFilter::class, arguments={"parameterName": "group_on", "overrideDefaultGroups": false, "whitelist": {"allowed_group"}})
* @ApiFilter(OrderFilter::class, properties={"value","createdAt","updatedAt","customer.name","customer.id","parameter.name","parameter.id","mode.name","mode.id"})
* @ApiFilter(SearchFilter::class, properties={"id": "exact", "value": "ipartial", "customer.name": "ipartial", "customer.id": "exact", "parameter.name": "ipartial", "parameter.id": "exact", "mode.name": "ipartial", "mode.id": "exact"})
* @ORM\Entity(repositoryClass="App\Repository\CustomersParametersRepository")
*/
class CustomersParameters
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"CustomersParameters:read","user:read"})
* @ApiProperty(identifier=true)
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=false)
* @Groups({"user:read","user:write"})
* @Assert\NotBlank()
*/
private $value;
/**
* @ORM\ManyToOne(targetEntity=Customer::class, inversedBy="param")
* @ORM\JoinColumn(nullable=false)
* @Groups({"user:read","user:write"})
* @Assert\NotBlank()
*/
private $customer;
/**
* @ORM\ManyToOne(targetEntity=Parameter::class, inversedBy="param")
* @ORM\JoinColumn(nullable=false)
* @Groups({"user:read","user:write"})
* @Assert\NotBlank()
*/
private $parameter;
/**
* @ORM\ManyToOne(targetEntity=Mode::class, inversedBy="param")
* @ORM\JoinColumn(nullable=false)
* @Groups({"user:read","user:write"})
* @Assert\NotBlank()
*/
private $mode;
/**
* @ORM\Column(type="datetime", nullable=false)
* @Groups({"user:read"})
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"user:read"})
*/
private $updatedAt;
我想在此组件中使用:
const CustomersParametersCreate =(props) => (
<Create {...props} title={"Creation d'un lien client/paramètre"}>
<SimpleForm toolbar={<Tools.CreateToolbar/>} warnWhenUnsavedChanges>
<ReferenceInput
label='Client'
source="customer.name"
reference="customers"
validate={required()}
filterToQuery={searchText => ({name: searchText, order: 'ASC', pagination: false})}
fullWidth
>
<AutocompleteInput name={'customer'} optionText={"name"} allowNull={false}/>
</ReferenceInput>
<ReferenceInput
label='Fonctionnement'
source="mode.name"
reference="modes"
validate={required()}
sort={{field: 'name', order: 'DESC'}}
fullWidth
>
<AutocompleteInput optionText={"name"} allowNull={false}/>
</ReferenceInput>
<ArrayInput label={"Paramètrage"} source={'parameter'}>
<SimpleFormIterator>
<ReferenceInput label='Paramètre' reference={'parameters'} source={'parameter.name'} filterToQuery={searchText => ({name: searchText, order: 'ASC', pagination: false})} fullWidth>
<SelectInput optionText={'name'} />
</ReferenceInput>
<TextInput source="value" label='Valeur' validate={required()} fullWidth/>
</SimpleFormIterator>
</ArrayInput>
</SimpleForm>
</Create>
);
如何使CustomerParameters
实体的“值”与参数链接?试试这个
{
"customer":"/api/customers/1",
"mode":"/api/modes/1",
"parameter": [
"/api/parameters/1",
"/api/parameters/2"
]
}
试试这个
{
"customer":"/api/customers/1",
"mode":"/api/modes/1",
"parameter": [
"/api/parameters/1",
"/api/parameters/2"
]
}
谢谢你的帮助。但在我的结构中,这不是大摇大摆所需要的价值观。我想更改我的
CustomersParameters
实体,并仅为每个参数的值添加一个新实体。custumer、mode和parameter是新实体还是现有实体?是。我有这些实体(基本表示):Mode(id,name,OneToMany=>target:CustomersParameters,mappedBy:Mode)Customer(id,name,gencod,OneToMany=>target:CustomersParameters,mappedBy:Customer)参数(id,name,helper,OneToMany=>target:CustomersParameters,mappedBy:Parameter)add cascade={“persis”}谢谢您的帮助。但在我的结构中,这不是大摇大摆所需要的价值观。我想更改我的CustomersParameters
实体,并仅为每个参数的值添加一个新实体。custumer、mode和parameter是新实体还是现有实体?是。我得到了这些实体(基本表示):Mode(id,name,OneToMany=>target:CustomersParameters,mappedBy:Mode)Customer(id,name,gencod,OneToMany=>target:CustomersParameters,mappedBy:Customer)参数(id,name,helper,OneToMany=>target:CustomersParameters,mappedBy:Parameter)add cascade={“persis”}
{
"customer":"/api/customers/1",
"mode":"/api/modes/1",
"parameter": [
"/api/parameters/1",
"/api/parameters/2"
]
}