as you can see, i used ‘text’ as search condition attribute expecting to use getText(), but findAll() creates and excecutes a DB query and wont look at model attributes at all, so an error occurs stating ‘text’ is not defined in table.
I can make autocompleteAction specific to this model to handle the issue, but i need it to be generic. i.e. action take model and attribute as parameters and return matching list, no matter attribute is in table or is a virtual one defined in model.
Yes, I’m doing this right now, but grouping all attributes in model as a virtual one, is more standard.
also, I use some characters to show between 3 strings, like ‘-’ or ‘\’ or space, and this should be determined in model class, but using 3 conditions, I have to set this connecting character in autocompleteAction, which is not it’s business.
I think it will never work with virtual attributes as they are created “on the fly” AFTER the model is loaded, so you can’t use them when searching. If your problem is merely related to the fact that your models will grow and the SQL queries quickly become complex than one idea could be to index your models with a search engine like Sphinx, Solr or ElasticSearch. There is a Sphinx extension for Yii out there and I use ElasticSearch a lot these days. This way you can use search functionalities that are (usually) superior to SQL fulltext searches.
@Haensel and @Dana, thank you for your help, I learned from your posts.
finally, I managed to handle the issue. logically, my model fields make a tree hierarchy. i.e. each title belongs to a group and each group belongs to a category. so, I change my table to an adjacency list(child-parent style), and use DB’s built in recursive query to get parents of each element that user selects (I use Postgresql, to achieve the same functionality in MySql, somebody can use nestedsetbehavior)