Replies: 2 comments
-
You can use the parameter Something like (adjust naming as wish) from typing import Optional, List
import ormar as orm
import sqlalchemy as sa
import databases as db
DB_URL = 'sqlite:///test.db'
database: db.Database = db.Database(DB_URL)
metadata: sa.MetaData = sa.MetaData()
class TeamTestKits(orm.Model):
class Meta:
tablename = "team_testkits"
metadata = metadata
database = db
class TestKit(orm.Model):
id: int = orm.UUID(primary_key=True)
slug: str = orm.String(index=True)
class Meta(orm.ModelMeta):
metadata = metadata
database = database
tablename = 'testkits'
class Team(orm.Model):
id: int = orm.UUID(primary_key=True)
name: Optional[str]= orm.String(nullable=True, index=True)
team_testkits: List[TestKit] = orm.ManyToMany(TestKit, through=TeamTestKits)
class Meta(orm.ModelMeta):
metadata = metadata
database = database
tablename = 'teams'
async def create():
engine = sa.create_engine(DB_URL)
await database.connect()
metadata.drop_all(engine)
metadata.create_all(engine)
await databae.disconnect()
if __name__ == '__main__':
import asyncio
asyncio.run(create()) Here I'm not using I think if you completely omit the AFAIK, the automatic name of the |
Beta Was this translation helpful? Give feedback.
-
You can do it like @igormorgado said but that will not help you in your case. There is an issue #137 for it and it's in development but it's a huge change in regard to the scope of the changes, so it will take some more time to finish. As of now, you should add an additional pk column that |
Beta Was this translation helpful? Give feedback.
-
I'm currently trying to migrate some models away from sqlalchemy and currently have a many to many relation with an association as follows:
What does the ormar equivalent look like as I can't customize the association tables name without creating a new model. If I do this I can't put more than one primary_key, postgres treats association tables as having two primary keys.
Beta Was this translation helpful? Give feedback.
All reactions