Skip to content

specify foreignKey#28

Open
diligiant wants to merge 1 commit intodavecheney:mainfrom
diligiant:foreignKey
Open

specify foreignKey#28
diligiant wants to merge 1 commit intodavecheney:mainfrom
diligiant:foreignKey

Conversation

@diligiant
Copy link
Copy Markdown

When it is not named after the owner’s type name plus its primary field name.

Fixes #18.

@davecheney
Copy link
Copy Markdown
Owner

Thank you for your PR. I'll have a close look at what indexes Gorm is generating by default and see if this helps.

@diligiant
Copy link
Copy Markdown
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

instance.admin.(email for example) returns the last user created

2 participants