pub
pub copied to clipboard
instance.admin.(email for example) returns the last user created
Hi,
That's probably a "gorm magic" issue and I really have no idea how to solve it. Check my test server (https://none.com/api/v1/instance/). You'll see that email, contact_account is myself although the serializer processes the i.Admin (admin@). When I check instances and accounts in Mariadb, this confirms that it holds the right info (see below).
Any hint/solution would be great.
thank you.
Frédéric
select admin_id from instances;
+--------------------+
| admin_id |
+--------------------+
| 109694405584505771 |
+--------------------+
select id, actor_id, email from accounts;
+--------------------+--------------------+--------------------+
| id | actor_id | email |
+--------------------+--------------------+--------------------+
| 109694405584505771 | 109694405584200435 | [email protected] |
select id,name from actors where id=109694405584200435;
+--------------------+-------+
| id | name |
+--------------------+-------+
| 109694405584200435 | admin |
+--------------------+-------+
thanks for spotting that; back in the day the instance admin was a total hack which was just finding a random account with a matching domain. I suspect that logic is still lurking around.
I was under the impression the gorm magic wasn't working as before adding a LocalUser account, the correct info were returned but if you think that's "intentional", I'm gonna find this culprit ;)
@davecheney I hope my PR will satisfy you ; I was really frustrated by this problem. I found 2 other occurrences (hoping I caught them all.)
Something puzzles me though: gorm documentation describes
type instance struct {
…
AdminID *snowflake.ID
Admin *Account
}
type Account {
snowflake.ID
}
as a Belongs To association, "the instance belongs to the admin account".
Shouldn't this be instead an Has One, "the instance has one admin account"? If so, one should take a look the the many associations in your schema.
my 2¢
Damnit, did I break that again?
It never worked (I found this when I first played with pub) as it never could (and I bet that's also true with Relationship & Status.) gorm is tricky (I almost rewrote with sqlc ;) here as its "convention" isn't "the previous field is named like the association field+primarykey". That's very subtle…
Regarding BelongsTo vs HasOne, I don't know if that changes anything today but isn't this a bet that gorm won't do things differently in the future?
I get very confused by HasOne vs BelongsTo in gorm.
you, me and a million people.