ApiLogicServer / ApiLogicServer-src

Create an executable project (API and Admin App) from a database or natural language prompt with 1 command, customize with declarative rules and Python in your IDE, containerize and deploy.
https://apilogicserver.github.io/Docs/
BSD 3-Clause "New" or "Revised" License
30 stars 5 forks source link

`APILogicServer create` fails if a foreign key column has the same name as the target table #38

Closed charliejharrison closed 9 months ago

charliejharrison commented 9 months ago

If a foreign key column has the same name as the target table it causes create to fail.

To take an example from the sample database: if Order.CustomerID was instead named Order.Customer, then create would throw an SQLAlchemy error:

sqlalchemy.exc.InvalidRequestError: back_populates on relationship 'Customer.OrderList' refers to attribute 'Order.customer' that is not a relationship.  The back_populates parameter should refer to the name of a relationship on the target class.

I think this is because when the model generation code tries to declare the relationship in the Order model using the target table name, but it finds a name clash with the column so appends a 1 to the name of the relationship. Something like this:

class Order():
    ...
    customer = Column(ForeignKey('Order.customer', ondelete='CASCADE'), nullable=False)
    ...
    customer1 : Mapped["Customer"] = relationship(back_populates=("OrderList"))
valhuber commented 9 months ago

Thanks for gift-wrapped bug report. I will save the wrapping.

Will look into it right away.

valhuber commented 9 months ago

Fixed in preview:

python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple ApiLogicServer==10.02.00

valhuber commented 9 months ago

Fixed in GA: 10.02.00