1

如何从 REST API 替换多对多连接表?

消除

foreach ($find_variant->getOptionValues() as $key => $option_data) {

$option = $em->getRepository('ISCoreBundle:OptionValue')->find($option_data->getId());

    if($option){
        $find_variant->removeOptionValue($option);
    }else{
        $this->json_status['status'] = 0;
        $this->json_status['message'] = 'Option Value not found!';
}                                   

更新

foreach ($serilize->option as $key => $option_data) {
        // code...
        $option = $em->getRepository('ISCoreBundle:OptionValue')->find($option_data->id);

        if($option) {
            $find_variant->addOptionValue($option);
        } else {
            $this->json_status['status'] = 0;
            $this->json_status['message'] = 'Option Value not found!';
        }                                   
    }

}

我认为这是一种丑陋的方式!什么是正确的方式?

4

0 回答 0