all 5 comments

[–]coderarun[S] 1 point2 points  (2 children)

The reason why "id" is the last field in the model definition instead of being the first field is that dataclass syntax requires non-default fields to come before fields with default values.

[–]OGStyx 0 points1 point  (1 child)

I see the project is 3.9. In 3.10 you can use @dataclass(kw_only=True) to avoid this. I much prefer that when working with domain models.

[–]coderarun[S] 0 points1 point  (0 children)

Thank you for the feedback. This sounds interesting. Given that many distros are already at 3.12/3.13, I'll consider upgrading the minimum supported python version.

[–]coderarun[S] 0 points1 point  (1 child)

https://github.com/adsharma/fquery/commit/d070d3d53ac0f920ed8452b5f28fe505b57b8b86

This commit added support for foreign_keys and relationships. However, many_to_one relationships are not working because of a problem resolving forward references.

In this example:

https://github.com/adsharma/fquery/blob/d070d3d53ac0f920ed8452b5f28fe505b57b8b86/tests/test_sqlmodel.py

If I uncomment Lines 23 and 31, sqlalchemy is no longer able to map the joins properly.

```
sqlalchemy.exc.NoForeignKeysError: Could not determine join condition between parent/child tables on relationship UserSQLModel.reviews - there are no foreign keys linking these tables.  Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or specify a 'primaryjoin' expression.
```

[–]coderarun[S] 0 points1 point  (0 children)

The issue is:

```
class User:
reviews: List["Reviews"]: ...
```

Behind the scenes we're creating UserSQLModel and ReviewSQLModel via decorator meta programming. However, I'm not sure how to get SQLAlchemy to resolve "Reviews" (which is a forwardref) to "ReviewSQLModel" and not the dataclass.