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

skipAttributes on SELECT (Phalcon 2.x)

Is there such a thing as skipAttributes on the SELECT (not just insert/update)

All my models extend a BaseModel which have some basic fields like id, createDate, editDate, active.

Some of my tables do NOT have all these fields. During insert/update, the skipAttributes() are working fine but it blow up during any type of fetch. I was thinking of doing something like beforeSelect() something like that to hook into to maybe even do something like

unset($this->createDate);

Not really familiar with the Zephir code to look deeper

The obvious solution (not preferred) would be to create 2 abstract classes instead of one and do one more extend

Thanks, Chris



5.7k
Accepted
answer

Are you using independent column mapping? https://docs.phalcon.io/en/latest/reference/models.html#independent-column-mapping

If you map the columns for each model, you shouldn't have any issues.



3.4k

Thanks! I am using some Annotation stuff (includes mapping the column fields) but manipulating the columnMap is the right way to go. I ended up creating an annotation @Skip and have the field not added to the columnMap -- this is a hack that I need to remove

Are you using independent column mapping? https://docs.phalcon.io/en/latest/reference/models.html#independent-column-mapping

If you map the columns for each model, you shouldn't have any issues.



5.7k

The nice thing about the dev tools is that you can get it to map everything for you. The only complaint I have with devtools though is that all-models doesn't have "mapcolumn" or "trace" as possible parameters.