I have 2 simple models. First, one is called Builds (mysql) and the second one is called SlotOptions (mongodb). Each build can have 5 assigned slots. Based on https://stackoverflow.com/a/55132863/2513428
select * from `builds` where `builds`.`id` = 37 limit 1
SlotOptions.find({"heroName":{"$in":[37]}},{"typeMap":{"root":"array","document":"array"}})
Table. build_slot_option (mysql)
+----------------+--------+----------------------------------------+
| Name | Type | Desc |
+----------------+--------+----------------------------------------+
| slot_option_id | char50 | // FK, Name of slot option f.e "Hero1" |
| build_id | int | // FK, Build id |
| pos | int | // Number 1-5 |
+----------------+--------+----------------------------------------+
slot_option_id - is a string that contains a hero name, it's not an ID in fact.
Example:
+----------------+----------+-----+
| slot_option_id | build_id | pos |
+----------------+----------+-----+
| Hero1 | 37 | 1 |
| Hero2 | 37 | 2 |
| Hero3 | 37 | 3 |
| Hero4 | 37 | 4 |
| Hero5 | 37 | 5 |
+----------------+----------+-----+
Table. Builds (mysql)
+------+------+------------------------+
| Name | Type | Desc |
+------+------+------------------------+
| id | int | // PK, of Builds Table |
| ... | ... | // and other columns |
+------+------+------------------------+
This is the build class, and usage example.
class BuildDB extends Model
{
use HybridRelations;
protected $connection = 'mysql';
public function slots()
{
return $this->belongsToMany(
SlotOptions::class, 'build_slot_option', 'build_id', 'slot_option_id'
);
}
}
BuildDB::with('slots')->find(5);
When it comes to the second query it should not insert the build id there {"$in":[37]}
just all the slot names, from tb build_slot_option slot_option_id column. For example {"$in":['Hero1','Hero2']}