也许我错过了你的问题,但你似乎把事情搞得太复杂了。使用农场模型获得所有农场的列表。使用此列表可在窗体中创建选择。
<select name="farm">
<option value="1">Farm 1</option>
<option value="2">Farm 2</option>
<option value="3">Farm 3</option>
</select>
当你保存你的动物时,你就有了它所属农场的主键。
$animal = $_POST;
if ( $animal->validate() ) {
$animal->save(); //saves all your animal data as well as the farm it belongs to.
}
else {
// show your view and display the animal data
}
<label>Animal Name</label><input type="text" value="<?php echo $animal->getValue('name') ?>">