0

I am sending data to the database by checking duplicate data. But I can't be inserting/updating data in the database.

protected function saveEntityFinish(array $entityData, $table) {
        $collection= $this->PostTableFactory->create();
        $item = $collection->getCollection();


        if ($entityData) {
            $tableName = $this->_connection->getTableName($table);
            $entityIn = [];
            $entityInup = [];
            foreach ($entityData as $id => $entityRows) {
                    foreach ($entityRows as $row) {
                        $item->addFieldToFilter('rule_id',$row['rule_id']);
                        $item->addFieldToFilter('store_id',$row['store_id']);

                        if(count($item->getData()) == 0){
                            $temp= $item->getData();
                            $logger->info('one');
                            $collection->setRuleId($row['rule_id']);
                            $collection->setStoreId($row['store_id']);
                            $collection->setStatus($row['status']);
                            $entityIn[] = $row;
                            $collection->save();
                        }else{
                            $entityInup = $row;


                            $collection = $this->PostTableFactory->create();
                            $collection->load($item->getData()[0]['p_id']);

                            $collection->setRuleId($entityInup['rule_id']);
                            $collection->setStoreId($entityInup['store_id']);
                            $collection->setStatus($entityInup['status']);
                            $entityIn[] = $entityInup;
                            $collection->save();

                        }

                    }
            }


        }
        return $this;
    }

can I get help on it? Thank you in advance

2 Answers 2

0

I have updated my value using CollectionFactory. You can give it a try

 $query = $this->_YourCollection->create()
                ->addFieldToFilter('field_id', $value)
                ->addFieldToFilter('filed',$value2)->getFirstItem();
            if ($query->getData()){
                if ($yourCondition){
                    $query->setData('field','valuefor update');
                    $query->save();
                }
            }
1
  • Thank you @Ghulam.M for responce, this filter method showing invalid Apr 20, 2019 at 5:48
0

To update a row we have to add that column id attached with updated data in that row will update the row

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.