Answer the question
In order to leave comments, you need to log in
Why are 2 entries added to the database instead of 1?
Good afternoon, I can not catch a double entry in the database.
В контроллере:
VisitService::newVisit();
в Визит сервисе:
public static function newVisit($page_id){
$model = new Statistics();
$model->load(self::getPlaceholder($page_id), '');
self::saveVisit($model);
}
private static function saveVisit($model){
if($model->validate() && $model->save()){
\Yii::debug('сохранение визита'); // пытаюсь посмотреть сколько раз будет в логах
return true;
}
return false;
}
INSERT INTO `statistics` (`page_id`, `type`, `ip`, `date`) VALUES (42, 0, '127.0.0.1', NOW())
Answer the question
In order to leave comments, you need to log in
Does the table have a primary key?
in general, insert or update - is determined on the basis of null === $_oldAttributes
it is filled during insert if there is a PC in the table.
if there is no PC and it cannot be added, you need to define your own getIsNewRecord() for the model and store some flag as an additional condition.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question