@@ -624,4 +624,53 @@ public function testTextBasedPrimaryKeyDuplicateKey() {
624624 $ this ->expectExceptionMessage ('UNIQUE constraint failed: my_text_table.my_pk ' );
625625 $ myTextTable2 ->save ();
626626 }
627+
628+ public function testWhereConditionWithSuppliedTableName () {
629+ $ user = new User (new PDO ('sqlite:test.db ' ));
630+ $ user ->name = 'demo ' ;
631+ $ user ->password = md5 ('demo ' );
632+ $ user ->insert ();
633+
634+ $ contact = new Contact (new PDO ('sqlite:test.db ' ));
635+ $ contact ->user_id = $ user ->id ;
636+ $ contact->
email =
'[email protected] ' ;
637+ $ contact ->address = 'test address ' ;
638+ $ contact ->insert ();
639+
640+ $ user
641+ ->select ('user.*, contact.email ' )
642+ ->join ('contact ' , 'contact.user_id = user.id ' )
643+ ->eq ('user.name ' , 'demo ' )
644+ ->find ();
645+
646+ $ this ->assertEquals ('demo ' , $ user ->name );
647+ $ this ->
assertEquals (
'[email protected] ' ,
$ user->
email );
648+ }
649+
650+ public function testWhereConditionWithFunctionName () {
651+
652+ $ this ->ActiveRecord ->execute ("CREATE TABLE IF NOT EXISTS json_test (
653+ id INTEGER PRIMARY KEY,
654+ data TEXT,
655+ created_dt TEXT
656+ ); " );
657+
658+ $ json = new class (new PDO ('sqlite:test.db ' )) extends ActiveRecord {
659+ public function __construct ($ pdo ) {
660+ parent ::__construct ($ pdo );
661+ $ this ->table = 'json_test ' ;
662+ $ this ->primaryKey = 'id ' ;
663+ }
664+ };
665+ $ json->
data =
'{"name": "demo", "email": "[email protected] "} ' ;
666+ $ json ->created_dt = gmdate ('Y-m-d H:i:s ' );
667+ $ json ->insert ();
668+ $ json
669+ ->select ('json_test.*, json_extract(data, "$.email") as email ' )
670+ ->eq ('json_extract(data, "$.name") ' , 'demo ' )
671+ ->find ();
672+
673+ $ this ->assertEquals ('demo ' , json_decode ($ json ->data )->name );
674+ $ this ->
assertEquals (
'[email protected] ' ,
$ json->
email );
675+ }
627676}
0 commit comments