-
Notifications
You must be signed in to change notification settings - Fork 88
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 support for 1 to many relationships #30
Labels
Projects
Comments
I would suggest that all of the models should be loaded into the main project file. #src/blog.cr
require "./models/*" |
can you require all subdirectories as well? does this work in crystal? |
found it: https://crystal-lang.org/docs/syntax_and_semantics/requiring_files.html require "./models/**" |
Both of those will work. |
I'll try and take a stab at this in the next few weeks. |
Closed
Closing since #52 was merged. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create two new macros:
belongs_to
andhas_many
This will create a mapping to the
post_id : Int64
field and generate a method that will query the parent and return it.This will create a method called comments that will query the children records.
Options to override the field names and types should be considered for legacy database mappings.
One of the difficulties is requiring the other model. Macros do not allow you to inject
require
into the class.Another issue is the N+1 queries for comments. I think we can find ways of optimizing this later.
The text was updated successfully, but these errors were encountered: