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

Column 'author' doesn't belong to any of the selected models (2)

Hello All,

I get this error message "Column 'author' doesn't belong to any of the selected models (2)" when select data from database using querybuilder as follow

     $builder = $this->modelsManager->createBuilder()
         ->from('Webapp\Frontend\Models\Blog')
         ->where('author = :author:',array("author" => $auth[id]))
         ->orderBy('Webapp\Frontend\Models\Blog.id');

     // Create a Model paginator, show 10 rows by page starting from $currentPage
     $paginator = new \Phalcon\Paginator\Adapter\QueryBuilder(
         array(
             "builder" => $builder,
             "limit"=> 10,
             "page" => $currentPage
         )
     );
     $page = $paginator->getPaginate();
     $this->view->setVar("page", $page);

I use the same method when select data from other table and they working fine but not work with my last create table.

class Blog extends \Phalcon\Mvc\Model
{

/**
 *
 * @var integer
 */
public $id;

/**
 *
 * @var integer
 */
public $author;

/**
 *
 * @var integer
 */
public $category;

/**
 *
 * @var string
 */
public $title;

/**
 *
 * @var string
 */
public $slug;

/**
 *
 * @var string
 */
public $intro;

/**
 *
 * @var string
 */
public $content;

public function initialize()
{

}

}

MySQL Column

  1. id int(11)
  2. author int(11)
  3. category int(11)
  4. title varchar(255)
  5. slug varchar(255)
  6. intro varchar(255)
  7. content longtext

What I do wrong on this query builder?

another question - what is meaning of (2) in "Column 'author' doesn't belong to any of the selected models (2)"?

Thank you for any help.



22.6k

Are you using database introspection? Note that if Phalcon has cached the structure of your table, it will only allow using the columns it knows about. Remove the cached introspection files and re-run your request to have them regenerated and it should work.



8.5k

Thank you dimhoLt , I think I not using database introspection and cached the structure of the table.



2.1k

Webapp\Frontend\Models\Blog.author?

are you using 2.0 by any chance?



8.5k
edited Feb '15

Currently I am using version 1.3.4, I use "Webapp\Frontend\Models{modelname}" with other tables and it work well.

Should I upgrade to 2.0?



8.5k
Accepted
answer

Thank you dimhoLt and 7thcubic, I found that it error because my mistake in model file which I wrong type namespace.