Comments (1)
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 anormar
model it's treated as normal pydantic model and in theory you can inherit from it, butormar
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 adid = Integer(primary_key=True)
field for you, as all models requires a pk, and this feature populates columns on through model inManyToMany
relations - For now
ormar
does 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 fromormar.Model
and declare an internalMeta
class with required params
So something like:
DATABASE_URL = "sqlite:///test.db"
database = databases.Database(DATABASE_URL)
metadata = sqlalchemy.MetaData()
class MainMeta(ormar.ModelMeta):
metadata = metadata
database = database
# not that db models should inherit from ormar.Model directly
class PositionOrm(ormar.Model):
class Meta(MainMeta):
pass
name: str = String(primary_key=True, max_length=50)
x: float = Float()
y: float = Float()
degrees: float = Float()
@pytest.fixture(autouse=True, scope="module")
def create_test_database():
engine = create_engine(DATABASE_URL)
metadata.create_all(engine)
yield
metadata.drop_all(engine)
@pytest.fixture(scope="function")
async def cleanup():
yield
async with database:
await PositionOrm.objects.delete(each=True)
@pytest.mark.asyncio
async def test_creating_a_position(cleanup):
async with database:
instance = PositionOrm(
name="my_pos",
x=1.0,
y=2.0,
degrees=3.0,
)
await instance.save()
assert instance.saved
assert instance.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.
from ormar.
Related Issues (20)
- Add `first_or_none`
- FastpAPI state has not database HOT 4
- How to configure alembic autogenerate with multiple model files HOT 5
- Error awaiting None
- Upgrade to SQLAlchemy 2.0 HOT 5
- Add SELECT DISTINCT feature to queryset
- Failing test: test_weakref_init
- Reverse relation not returned from get_pydantic
- Low performance on select_all() call HOT 1
- Nullable ForeignKey field does not get updated to null
- The future of ORMAR HOT 6
- Support specifying a table comment
- Please support pydantic-2.x HOT 3
- New release with the latest dependency upgrades HOT 2
- Unresolved attribute reference 'objects'
- Model field types and pyright
- v0.20.0 is released as stable instead of beta HOT 3
- Allow tables without primary key
- Allow Pydantic 1.10.13 to mitigate security risk
- Specify a different field to select relations into
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ormar.