class Model_Photo extends Orm\Model { protected static $_properties = array('id', 'user_id', 'full', 'med', 'icon', 'map', 'place_id', 'created_at', 'updated_at'); protected static $_observers = array( 'Orm\Observer_CreatedAt' => array('before_insert'), 'Orm\Observer_UpdatedAt' => array('before_save'), ); protected static $_belongs_to = array( 'user' => array( 'key_from' => 'user_id', 'model_to' => 'Model_Profile', 'key_to' => 'user_id', 'cascade_save' => false, 'cascade_delete' => false, ), 'place' => array( 'key_from' => 'place_id', 'model_to' => 'Model_Place', 'key_to' => 'id', 'cascade_save' => false, 'cascade_delete' => false, ), 'promoted' => array( 'key_from' => 'id', 'model_to' => 'Model_Promote_Photo', 'key_to' => 'photo_id', 'cascade_save' => false, 'cascade_delete' => true, )); } class Model_Promote_Photo extends Orm\Model { protected static $_properties = array('id', 'user_id', 'photo_id', 'created_at', 'updated_at'); protected static $_observers = array( 'Orm\Observer_CreatedAt' => array('before_insert'), 'Orm\Observer_UpdatedAt' => array('before_save'), ); protected static $_belongs_to = array( 'user' => array( 'key_from' => 'user_id', 'model_to' => 'Model_Profile', 'key_to' => 'user_id', 'cascade_save' => false, 'cascade_delete' => false, ), 'photo' => array( 'key_from' => 'photo_id', 'model_to' => 'Model_Photo', 'key_to' => 'id', 'cascade_save' => false, 'cascade_delete' => false) ); }
$photos = Model_Photo::find() ->where('user_id', $id) ->related('promoted',array('where'=>array('user_id',$this->user_id))) ->order_by('created_at', 'desc') ->get();
It looks like you're new here. If you want to get involved, click one of these buttons!