gpt4 book ai didi

forms - 多对多对嵌入式形式

转载 作者:行者123 更新时间:2023-12-02 04:07:00 24 4
gpt4 key购买 nike

我有三个简单的表格(比赛,裁判,运动员),其中的列分别是ID和名称。

还有另外两个表(race_judge和race_athlete),通过Advanced Forms中所述的嵌入式形式,我在前端应用程序中通过种族形式将比赛与许多裁判和比赛与许多运动员联系起来;这两张表都有一些额外的字段(例如,关于比赛的裁判说明和运动员的比赛编号),可以用嵌入的形式填写。

现在,我想为最后一个表格“race_judge_athlete”构建一个嵌入式表格,在该表格中,每个参加比赛的法官都可以对参加该比赛的每个运动员进行投票,我想用一个表格填写数字。

我将如何使用symfony +教义形式进行操作?

更新:当我插入新的比赛(通过RaceForm)时,由于运动员和裁判模型中的关系,裁判和运动员自动添加到race_judge和race_athlete(如果从选择小部件中选择)中,但是在race_judge_athlete中不会发生。

这是schema.yml:


Race:
columns:
name: string(255)
Athlete:
columns:
name: string(255)
relations:
RaceAthlete:
foreignAlias: RaceAthlete
class: Race
refClass: RaceAthlete
local: athlete_id
foreign: race_id
Judge:
columns:
name: string(255)
relations:
RaceJudge:
foreignAlias: RaceJudge
class: Race
refClass: RaceJudge
local: judge_id
foreign: race_id

RaceJudge:
columns:
race_id: integer
judge_id: integer
judge_notes: string
relations:
Race:
class: Race
local: race_id
Judge:
class: Judge
local: judge_id
RaceAthlete:
columns:
race_id: integer
athlete_id: integer
athlete_number: integer
relations:
Race:
class: Race
local: race_id
Athlete:
class: Athlete
local: athlete_id

RaceJudgeAthlete:
columns:
race_id: integer
judge_id: integer
athlete_id: integer
score: double
relations:
Race:
class: Race
local: race_id
Judge:
class: Judge
local: judge_id
Athlete:
class: Athlete
local: athlete_id

最佳答案

我整理了一个可行的快速技巧,但它真是丑陋!
我仍在寻找一个干净的实现,但是现在可以。

在RaceForm.class.php中,我以这种方式覆盖doSave函数:
我得到了由RaceSave中的doSave保存的RaceJudge和RaceAthlete集合,并手动创建了丢失的集合,删除了实际的RaceJudgeAthlete集合,并将手动创建的集合保存到了空的RaceJudgeAthlete集合中。

这是代码:



protected function doSave($con = null)
{
$this->saveRaceJudgeList($con);
$this->saveRaceAthleteList($con);

parent::doSave($con);
$this->saveRaceJudgeAthlete();
}

public function saveRaceJudgeAthlete()
{
$race = $this->getObject();
$RaceJudgeAthlete_collection = new Doctrine_Collection('RaceJudgeAthlete');
$i = 0;
foreach ($race->RaceJudge as $judge)
{
foreach ($race->RaceAthlete as $athlete)
{
$RaceJudgeAthlete_collection[$i]->setRaceId($race->getId());
$RaceJudgeAthlete_collection[$i]->setJudgeId($judge->judge_id);
$RaceJudgeAthlete_collection[$i]->setAthleteId($athlete->athlete_id);

$i++;
}
}

$race->RaceJudgeAthlete->delete();
$race->RaceJudgeAthlete = $RaceJudgeAthlete_collection;
$race->RaceJudgeAthlete->save();
}

关于forms - 多对多对嵌入式形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7122347/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com