It is necessary to make left join manually in criteria. I do this:

$criteria->join = "LEFT OUTER JOIN ". OfferBlockAbuse::model()->tableName()." `BlockedOffers` ON ( BlockedOffers.publisher_id = :pub_account_id AND BlockedOffers.type_publisher_id = 'Account' OR BlockedOffers.publisher_id = :pub_profile_id AND BlockedOffers.type_publisher_id = 'Profile' ) AND ( (BlockedOffers.item_id = t.id AND BlockedOffers.type_item_id = 'Offer') OR (BlockedOffers.item_id = Account.id AND BlockedOffers.type_item_id = 'Account') OR (BlockedOffers.item_id = company.id AND BlockedOffers.type_item_id = 'Profile') ) AND BlockedOffers.is_blocked = 'Yes' AND BlockedOffers.show_for_pub = 'No'"; 

The fact is that the criteria joins more relations . For example Account . And this join in the first request and Account.id he still does not see.

How to put this join at the end of the request? Or how to write such a complex communication model?

    1 answer 1

    Removed answer from question body

    Solved the problem as follows:

     relations() { ... 'BlockedOffers'=>array(self::HAS_ONE, 'OfferBlockAbuse', '', 'together'=>true), } $criteria->with = array( ... 'BlockedOffers' => array( 'select' => 'id', 'on'=>" ( BlockedOffers.publisher_id = :pub_account_id AND BlockedOffers.type_publisher_id = 'Account' OR BlockedOffers.publisher_id = :pub_profile_id AND BlockedOffers.type_publisher_id = 'Profile' ) AND ( (BlockedOffers.item_id = t.id AND BlockedOffers.type_item_id = 'Offer') OR (BlockedOffers.item_id = Account.id AND BlockedOffers.type_item_id = 'Account') OR (BlockedOffers.item_id = company.id AND BlockedOffers.type_item_id = 'Profile') ) AND BlockedOffers.is_blocked = 'Yes' AND BlockedOffers.show_for_pub = 'No' " ), ) 

    I did not know that you can leave an empty link.