#Object getting added to multiple relations when I am only adding to 1 (Sqlite database)

1 messages · Page 1 of 1 (latest)

robust basin
#

So i have this super weird bug. I am using tortoise orm (just like django but async) for my sqlite db

This is the giveaway model

class Giveaway(Model):

    msgid = fields.BigIntField(unique=True, null=True)
    guild: fields.ForeignKeyRelation[GuildDB] = fields.ForeignKeyField(
        "models.GuildDB", related_name="giveaways", on_delete=fields.CASCADE
    )
    channelid = fields.BigIntField()
    hostid = fields.BigIntField()
    prize = fields.CharField(max_length=128)
    winner_count = fields.IntField()
    duration = fields.IntField()  # in seconds
    end_timestamp = fields.BigIntField()  # in seconds
    ended = fields.BooleanField(default=False)
    amari_level = fields.IntField(default=0)
    amari_weekly = fields.IntField(default=0)
    required_roles: fields.ManyToManyRelation[RoleDB] = fields.ManyToManyField(
        "models.RoleDB", related_name="required_giveaways"
    )
    bypass_roles: fields.ManyToManyRelation[RoleDB] = fields.ManyToManyField(
        "models.RoleDB", related_name="bypass_giveaways"
    )
    blacklist_roles: fields.ManyToManyRelation[RoleDB] = fields.ManyToManyField(
        "models.RoleDB", related_name="blacklisted_giveaways"
    )
    users: fields.ManyToManyRelation[UserDB] = fields.ManyToManyField(
        "models.UserDB", related_name="giveaways_joined"
    )

when i create a giveaway, if i have required roles, bypass roles, blacklist roles, etc ; I create an entry for them in the db and then add them to the respective relation. For eg-

        if required_roles:
            required_roles_list = await self.parse_roles(
                required_roles, ctx.guild, as_db=True
            ) # this is a function i made that creates and returns me the db objects 

            await gaw.required_roles.add(*required_roles_list)

The issue is,** the roles get added to bypass roles and blacklist roles too** for some reason. This is breaking my logic. Help appreciated

#

Object getting added to multiple relations when I am only adding to 1 (Sqlite database)

robust basin
#

fukin hell i think i may need to ditch orms and use raw sql

#

or wait. i think i can have another table rather than this weird approach i am having

#

where column1 is a Giveaway FK, column2 is RoleFK and column3 is the State (bypass, blacklist, required etc)

#

should this work?

robust basin
#

No help here but i got it working

#

Its cuz many to many is just a table with 2 foreign keys

#

the db nor the orm know which field it was attached to

#

i just made my own table had ad 2 FK and another column to decide required/bypass/blacklist

#

that was the trick