-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log Record Can Have Many Employees (Part 1) (#239)
* so many whimsical magical wonderful changes * run the linter
- Loading branch information
Connor Bechthold
authored
Apr 21, 2024
1 parent
d1f9f1f
commit 4315888
Showing
14 changed files
with
211 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from sqlalchemy import inspect | ||
from sqlalchemy.orm.properties import ColumnProperty | ||
|
||
from . import db | ||
|
||
|
||
class LogRecordAttnTos(db.Model): | ||
__tablename__ = "log_record_attn_tos" | ||
|
||
id = db.Column(db.Integer, primary_key=True, nullable=False) | ||
log_record_id = db.Column( | ||
db.Integer, db.ForeignKey("log_records.log_id"), nullable=False | ||
) | ||
attn_to_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False) | ||
|
||
def to_dict(self, include_relationships=False): | ||
# define the entities table | ||
cls = type(self) | ||
|
||
mapper = inspect(cls) | ||
formatted = {} | ||
for column in mapper.attrs: | ||
field = column.key | ||
attr = getattr(self, field) | ||
# if it's a regular column, extract the value | ||
if isinstance(column, ColumnProperty): | ||
formatted[field] = attr | ||
# otherwise, it's a relationship field | ||
# (currently not applicable, but may be useful for entity groups) | ||
elif include_relationships: | ||
# recursively format the relationship | ||
# don't format the relationship's relationships | ||
formatted[field] = [obj.to_dict() for obj in attr] | ||
return formatted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
backend/migrations/versions/51ad56d133e9_create_log_records_attn_to_junction_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""create log records attn to junction table | ||
Revision ID: 51ad56d133e9 | ||
Revises: eff8a5a7fda3 | ||
Create Date: 2024-04-21 00:02:19.646800 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "51ad56d133e9" | ||
down_revision = "eff8a5a7fda3" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"log_record_attn_tos", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("log_record_id", sa.Integer(), nullable=False), | ||
sa.Column("attn_to_id", sa.Integer(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["attn_to_id"], | ||
["users.id"], | ||
), | ||
sa.ForeignKeyConstraint( | ||
["log_record_id"], | ||
["log_records.log_id"], | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table("log_record_attn_tos") | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.