We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Model can not see table when save() but see when find()

Hey guys! It's me)

A have a code:

$lead = OfficeStats::findFirst([
        'partner = 1 and order_id = ?0',
        'bind' => [$orderId]
]);
echo $lead->id; // 5 (it's really)
$lead->status_text = 'approved';
if($lead->save()) { // Exception: Table '' doesn't exist in database when dumping meta-data for App\Models\OfficeStats
    // ...
}

Why exception table "" ?

OfficeStats.php:

<?php

    /** 
    *   Статистика по заказам
    */

    namespace App\Models;

    use Phalcon\Mvc\Model;

    class OfficeStats extends Model {

        public function initialize() {

            $this->setSource('office_stats'); 

        }

    }

The first time in 3 years of working with a phalcon I encounter such behavior.



22.7k
Accepted
answer

does this work?

   public function getSource()
    {
        return 'office_stats';
    }

Yes, it helped. but I'm wondering what's wrong with my version, which worked for centuries.

edited Sep '17

Have you upgraded something on your stack just recently?

Phalcon\Mvc\Model\Manager in services container, how does it look like?

 *
 * This components controls the initialization of models, keeping record of relations
 * between the different models of the application.
 *
 * A ModelsManager is injected to a model via a Dependency Injector/Services Container such as Phalcon\Di.