You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, thanks for catching that up - fix that in Model.object.create() but didn't in Model.save() before.
Should be fixed now -> please update to latest version (0.5.1) and give it a try.
Also please notice that in your example the DbModel class is redundant.
If there is no Meta class declared on an ormar model it's treated as normal pydantic model and in theory you can inherit from it, but ormar redeclares the fields so there is no much use for this
If you declare a Meta and not declare any fields on model - ormar will ad id = Integer(primary_key=True) field for you, as all models requires a pk, and this feature populates columns on through model in ManyToMany relations
For now ormardoes not support model inheritance - so you cannot get multi-table models etc. For now each ormar.Model is a separate table in db.
Therefore all ormar models should inherit directly from ormar.Model and declare an internal Meta class with required params
So something like:
DATABASE_URL="sqlite:///test.db"database=databases.Database(DATABASE_URL)
metadata=sqlalchemy.MetaData()
classMainMeta(ormar.ModelMeta):
metadata=metadatadatabase=database# not that db models should inherit from ormar.Model directlyclassPositionOrm(ormar.Model):
classMeta(MainMeta):
passname: str=String(primary_key=True, max_length=50)
x: float=Float()
y: float=Float()
degrees: float=Float()
@pytest.fixture(autouse=True, scope="module")defcreate_test_database():
engine=create_engine(DATABASE_URL)
metadata.create_all(engine)
yieldmetadata.drop_all(engine)
@pytest.fixture(scope="function")asyncdefcleanup():
yieldasyncwithdatabase:
awaitPositionOrm.objects.delete(each=True)
@pytest.mark.asyncioasyncdeftest_creating_a_position(cleanup):
asyncwithdatabase:
instance=PositionOrm(
name="my_pos",
x=1.0,
y=2.0,
degrees=3.0,
)
awaitinstance.save()
assertinstance.savedassertinstance.name=="my_pos"
Now it should pass.
BTW. Thanks for the nice words! 😄 If you like the package consider starring it and spreading the news around - I am trying to get some traction and build a community around it to quicker catch bugs like this one (thanks again for catching!) and maybe also get some contributors for further development.
In the code sample below the test fails since the instance receives the item_id
Error message:
BTW: Awesome library. I am looking forward to start using it :)
The text was updated successfully, but these errors were encountered: