Some AR help is needed


I have a small problem with AR Relations. This is my case:

             // Get keyword

             $keyword = $_POST['keyword'];


             // Build documents criteria

             $docCriteria = new CDbCriteria;

             $docCriteria->condition = 'Documents.title LIKE :keyword OR documentsTags.tag LIKE :keyword';

             $docCriteria->params = array(':keyword' => (string)$keyword . '%');

             $docCriteria->select = 'id, title';

             $docCriteria->order = 'title ASC';

             $docCriteria->limit = 10;


             // Get documents

             $Documents = Documents::model()->with('documentsTags')->together()->findAll($docCriteria);


Documents relation:

              'documentsTags'=>array(self::MANY_MANY, 'Tags', 'DocumentsTags(tagId, documentId)'),


What i’m trying to do is to search and get results from where Documents.title is like keyword or where Tags.tag is like keyword.

How am i suppose to go about with AR?



I think you need to merge the two result sets, or use DAO since this use case is not very familiar with AR.

Yeah i was thinking of mergin the results but then it would be messed up if we would later on want to add pagination.

Any idea on how i could implement this without a too much performance loss in SQL? I still have some things to learn when it comes to this. :)