Commit a5188f1f authored by Qiang Xue's avatar Qiang Xue

Fixes #1457: support string representation of AR.

parent 72db6ffb
...@@ -92,6 +92,17 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface ...@@ -92,6 +92,17 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
private $_related = []; private $_related = [];
/**
* Returns the string representation of this AR instance.
* The default implementation will return the primary key (or JSON representation of the primary key if it is composite).
* @return string the string representation of this AR instance.
*/
public function __toString()
{
$pk = $this->getPrimaryKey();
return is_array($pk) ? json_encode($pk) : $pk;
}
/** /**
* Creates an [[ActiveQuery]] instance for query purpose. * Creates an [[ActiveQuery]] instance for query purpose.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment