Originally posted by **edimedia** May 25, 2024
Hi !
I think the related manager is not provided on object when this one is retrieved from DB, look at this:
models.py
db, registry = get_db_connection()
class World(Model):
id = fields.IntegerField(primary_key=True)
name = fields.CharField(max_length=255)
class Meta:
registry = registry
class Hello(Model):
id = fields.IntegerField(primary_key=True)
name = fields.CharField(max_length=255)
worlds = fields.ManyToManyField(World, related_name="hellos")
class Meta:
registry = registry
test_many2many_create.py
world = await World.query.create(name='Hearth')
hello = await Hello.query.create(name='King')
await hello.worlds.add(world) # It works correctly
test_many2many_retrieve.py
h = await Hello.query.get(id=1)
w = await World.query.get(id=1)
await h.worlds.remove(w) # AttributeError: 'NoneType' object has no attribute 'remove'
And when i'm looking for a sample code in `edgy/tests/foreign_keys/test_many_to_many.py`, i see there's no test about retrieve (get or filter method).
Thank you.
Discussed in https://github.com/tarsil/edgy/discussions/98