Skip to content

Instantly share code, notes, and snippets.

@cornernote
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cornernote/73d9b33c85b061a81d27 to your computer and use it in GitHub Desktop.
Save cornernote/73d9b33c85b061a81d27 to your computer and use it in GitHub Desktop.
orOnCondition relation

what do i put in $link to get something like: WHERE (1=1) AND (...my or condition...) ?

the current relation does:

SELECT * FROM audit_field WHERE (1=0) AND (...my or conditions...)
<?php
class Job extends \yii\db\ActiveRecord
{
public function getAuditFields()
{
$link = [];
return $this->hasMany(AuditField::className(), $link)
->orOnCondition([
'audit_field.model_id' => $this->job_id,
'audit_field.model_name' => get_class($this),
])
->orOnCondition([
'audit_field.model_id' => [1, 2, 3],
'audit_field.model_name' => 'app\models\JobTech',
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment