| 1 | |
|---|
| 2 | from elixir import * |
|---|
| 3 | from sqlalchemy import * |
|---|
| 4 | |
|---|
| 5 | class User(Entity): |
|---|
| 6 | docs = ManyToMany("Document", table="document_sharer", |
|---|
| 7 | local_colname="user_id", remote_colname="document_id") |
|---|
| 8 | |
|---|
| 9 | document_sharer = Table('document_sharer', |
|---|
| 10 | metadata, |
|---|
| 11 | Column('id', Integer, primary_key=True, autoincrement=True), |
|---|
| 12 | Column('user_id'), |
|---|
| 13 | Column('document_id'), |
|---|
| 14 | Column("owner", Boolean, server_default="false"), |
|---|
| 15 | UniqueConstraint("document_id", "user_id"), |
|---|
| 16 | ) |
|---|
| 17 | |
|---|
| 18 | class Document(Entity): |
|---|
| 19 | sharers = ManyToMany("User", table=document_sharer, |
|---|
| 20 | local_colname="document_id", remote_colname="user_id") |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | metadata.bind = "sqlite://" |
|---|
| 24 | setup_all() |
|---|