Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Relationship Support in Auto Generated Endpoints #24

Open
neatek opened this issue Mar 7, 2024 · 3 comments
Open

Add Relationship Support in Auto Generated Endpoints #24

neatek opened this issue Mar 7, 2024 · 3 comments
Labels
Automatic Endpoint Related to automatic endpoint creation functionality enhancement New feature or request

Comments

@neatek
Copy link

neatek commented Mar 7, 2024

Does FastCRUD work with relationship in SQLAlchemy?

class Car(Base):
    brand_id = Column(Integer, ForeignKey("car_brands.id"), nullable=False)
    body_type_id = Column(Integer, ForeignKey("car_body_types.id"), nullable=False)
    body_type = relationship("CarBodyType", backref="cars")
    brand = relationship("CarBrand", backref="cars")

Description
If you use get_multi, then a list is displayed without support for models that belong to this model

Additional context
The expectation was that if you add a relationship to the SQLalchemy model, then this relationship will also appear in the list after get_multi

@igorbenav igorbenav added the enhancement New feature or request label Mar 7, 2024
@igorbenav
Copy link
Owner

FastCRUD CRUD utilities work (with get_joined, get_multi_joined), but not the auto generated endpoints. It's a good feature to add though

@igorbenav igorbenav changed the title sqlalchemy relationship Add Relationship Support in Auto Generated Endpoints Mar 7, 2024
@neatek
Copy link
Author

neatek commented Mar 9, 2024

Hello,

car_models = await car_crud.get_multi_joined(
    db,
    join_model=models.CarBrand,
    join_prefix="brand_",
    user_id=credentials["id"],
)

is working well. but what i need to do if i have 2 joined models ?
not only models.CarBrand, but also models.CarBodyType

can you give a short code example?

Thank you!

@igorbenav
Copy link
Owner

It's not supported currently, but it's easy to fix. I'll patch it next week.

@igorbenav igorbenav added the Automatic Endpoint Related to automatic endpoint creation functionality label Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Automatic Endpoint Related to automatic endpoint creation functionality enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants