Here is my schemes：

user\_familiarity
-----------------

`id, item_type, item_id, score, custom_score , ...`

word
----

`id , ...`

user\_familiarity stores familiarity score of any object, which can identified by (item\_type, item\_id)

for example: 

item\_type = 1001, item\_id = 16 means table `word` and row's id is 16

Here is my code to select words with it's familiarity score:

```
$fam_table = UserFamiliarityModel::getTableName();
    return
        $query
        ->leftJoin($fam_table, function ($join) use($fam_table) {
            $join
            ->on(WordModel::getTableName() . '.id' ,'=',  "${fam_table}.item_id")
            ->on($fam_table . '.item_type' ,  1001);
        })
        ->addSelect(["${fam_table}.score", "${fam_table}.custom_score"]);

```

here is the sql that has been executed:

```
...
FROM
`word`
LEFT JOIN `user_familiarity` 
ON 
    `word`.`id` = `user_familiarity`.`item_id` 
AND `user_familiarity`.`item_type` = `1001`

```

and get errors :

> 
> Column not found: 1054 Unknown column '1001' 
> 
> 
>