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

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();
                }
            }
  • Thank you @Ghulam.M for responce, this filter method showing invalid – Praveen Negimani Apr 20 at 5:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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