Untitled
unknown
plain_text
a year ago
5.7 kB
4
Indexable
users_country.py:
from datetime import datetime
from typing import List
from sqlalchemy import TIMESTAMP, ForeignKeyConstraint, Index, Integer, String
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy.orm.base import Mapped
from .base import Base
class UsersCountry(Base):
__tablename__ = "mdm_users_countries"
__table_args__ = (
ForeignKeyConstraint(
["COUNTRY_ID"], ["mdm_countries.COUNTRY_ID"], name="CNTRY_ID"
),
ForeignKeyConstraint(
["USER_ID"], ["mdm_users.MDM_USER_ID"], name="USER_ID_CONTRY"
),
Index("CNTRY_ID_idx", "COUNTRY_ID"),
Index("USER_ID_CONTRY_idx", "USER_ID"),
)
id: Mapped[int] = mapped_column("USER_CNTRY_ID", Integer, primary_key=True)
user_id: Mapped[int] = mapped_column("USER_ID", Integer, nullable=False)
country_id: Mapped[int] = mapped_column("COUNTRY_ID", Integer, nullable=False)
created_date: Mapped[datetime] = mapped_column(
"CREATED_DATE", TIMESTAMP, nullable=False
)
created_by_id: Mapped[str] = mapped_column(
"CREATED_BY_ID", String(50), nullable=False
)
updated_date: Mapped[datetime] = mapped_column(
"UPDATED_DATE", TIMESTAMP, nullable=False
)
updated_by_id: Mapped[str] = mapped_column(
"UPDATED_BY_ID", String(50), nullable=False
)
countries: Mapped["Country"] = relationship(
"Country", back_populates="users_countries"
)
users: Mapped["User"] = relationship("User", back_populates="users_countries")
product: Mapped["Product"] = relationship(
"Product", back_populates="users_country"
)
product.py:
from datetime import datetime
from typing import List
from sqlalchemy import TIMESTAMP, BigInteger, Index, Integer, String, Text, ForeignKey
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy.orm.base import Mapped
from .base import Base
class Product(Base):
__tablename__ = "mdm_product"
__table_args__ = (
Index("MDM_ID", "MDM_ID"),
Index("REQUEST_STATUS_ID_idx", "REQUEST_STATUS_ID"),
)
id: Mapped[int] = mapped_column("RECORD_ID", BigInteger, primary_key=True)
mdm_id: Mapped[int] = mapped_column("MDM_ID", Integer, nullable=False)
series_id: Mapped[int] = mapped_column("SERIES_ID", Integer, nullable=False)
country_id: Mapped[int] = mapped_column("COUNTRY_ID", Integer, nullable=False)
product_name: Mapped[str] = mapped_column(
"PRODUCT_NAME", String(255), nullable=False
)
request_status_id: Mapped[int] = mapped_column(
"REQUEST_STATUS_ID", Integer, nullable=False
)
current_record: Mapped[int] = mapped_column(
"CURRENT_RECORD", Integer, nullable=False
)
last_active: Mapped[int] = mapped_column("LAST_ACTIVE", Integer, nullable=False)
is_deleted: Mapped[int] = mapped_column("IS_DELETED", Integer, nullable=False)
created_date: Mapped[datetime] = mapped_column(
"CREATED_DATE", TIMESTAMP, nullable=False
)
created_by_id: Mapped[str] = mapped_column(
"CREATED_BY_ID", String(50), nullable=False
)
updated_date: Mapped[datetime] = mapped_column(
"UPDATED_DATE", TIMESTAMP, nullable=False
)
updated_by_id: Mapped[str] = mapped_column(
"UPDATED_BY_ID", String(50), nullable=False
)
reltio_id: Mapped[str] = mapped_column("RELTIO_ID", String(255))
group_type: Mapped[str] = mapped_column("GROUP_TYPE", String(25))
janssen_mstr_prdct_nm: Mapped[str] = mapped_column(
"JANSSEN_MSTR_PRDCT_NM", String(150)
)
product_phase: Mapped[str] = mapped_column("PRODUCT_PHASE", String(50))
jnj_full_compound_id: Mapped[str] = mapped_column(
"JNJ_FULL_COMPOUND_ID", String(50)
)
generic_name: Mapped[str] = mapped_column("GENERIC_NAME", String(150))
jnj_flag: Mapped[str] = mapped_column("JNJ_FLAG", String(4))
th_area: Mapped[int] = mapped_column("TH_AREA", Integer)
product_status: Mapped[str] = mapped_column("PRODUCT_STATUS", String(25))
ta_sub_type: Mapped[str] = mapped_column("TA_SUB_TYPE", Text)
downstream_publish: Mapped[List["DownstreamPublish"]] = relationship(
"DownstreamPublish", uselist=True, back_populates="product"
)
product_fields: Mapped[List["ProductField"]] = relationship(
"ProductField", uselist=True, back_populates="product"
)
downstream_products: Mapped[List["DownstreamProduct"]] = relationship(
"DownstreamProduct", uselist=True, back_populates="product"
)
product_category: Mapped[List["ProductCategory"]] = relationship(
"ProductCategory", uselist=True, back_populates="product"
)
status: Mapped[List["Status"]] = relationship(
"Status", uselist=True, back_populates="product"
)
therapeutic: Mapped[List["Therapeutic"]] = relationship(
"Therapeutic", uselist=True, back_populates="product"
)
users_country: Mapped["UsersCountry"] = relationship(
"UsersCountry", uselist=True, back_populates="product"
)
I am getting the following error:
{
"data": null,
"errors": [
{
"message": "Could not determine join condition between parent/child tables on relationship Product.users_country - there are no foreign keys linking these tables. Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or specify a 'primaryjoin' expression.",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"productData"
]
}
]
}Editor is loading...
Leave a Comment