pub
pub copied to clipboard
specify foreignKey
Thank you for your PR. I'll have a close look at what indexes Gorm is generating by default and see if this helps.
You might find this interesting ; Here is what gorm does without and with "foreignKey:AdminID".
SELECT * FROM `actors` WHERE `actors`.`id` IN (\"110163848238256418\",\"110163851895700147\")
SELECT * FROM `accounts` WHERE `accounts`.`instance_id` = \"110163848239938280\"
SELECT * FROM `instance_rules` WHERE `instance_rules`.`instance_id` = \"110163848239938280\"
SELECT * FROM `instances` WHERE domain = \"example.com\" LIMIT 1
Here Preload(Admin) fetches all the actors (first admin, then me). I guess instance.Admin is me because that's the last loaded.
SELECT * FROM `actors` WHERE `actors`.`id` = \"110163848238256418\"
SELECT * FROM `accounts` WHERE `accounts`.`id` = \"110163848240493252\"
SELECT * FROM `instance_rules` WHERE `instance_rules`.`instance_id` = \"110163848239938280\"
SELECT * FROM `instances` WHERE domain = \"example.com\" LIMIT 1
Here Preload("Admin") only fetches the actor whose ID is AdminID
BTW, I also replaced Preload("Admin") by Joins("Admin") (you do this here) in the above cases: the first 3 calls are the same, the fourth one being replaced by something very long!