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

Use schema.cr instead of mappings? #11

Open
watzon opened this issue Jun 12, 2017 · 12 comments
Open

Use schema.cr instead of mappings? #11

watzon opened this issue Jun 12, 2017 · 12 comments
Assignees

Comments

@watzon
Copy link

watzon commented Jun 12, 2017

This a more of a question/request, but have you considered using a schema.cr file instead of a mapping macro inside of the model? I realize it would be a big change, but it would bring an important benefit, the ability to have the model definition update automatically. It also makes the model files look a little less cluttered.

Obviously, the one downside to this is that you don't have everything to do with the model all in one place, but I feel like it would be an ok tradeoff.

Thoughts?

@imdrasil
Copy link
Owner

@watzon really interesting thought but it needs to make database structure analyzer. Will take a look when will got free time

@imdrasil
Copy link
Owner

problem could be with allowing manual overriding fields under the model as well

@thomasnal
Copy link
Contributor

In case you would be looking into this, I would suggest to keep the model related code to models and extract the mapping using modules for those who feel clutter if there is any way,

class User < Jennifer::Model::Base
  include UserMapping
end

src/user/user_mapping.cr:

module UserMapping
  mapping(
    id: { type: Int32, primary: true }
  )
end

I see this as a cosmetic change rather than an improvement at this stage.

@z64
Copy link
Contributor

z64 commented Aug 29, 2017

@thomasnal I think you misunderstand the direction of the issue.

The proposal is to have Jennifer analyze the database itself and build the mapping for you, such that you don't need to do mapping() at all, and it would "magically" update with any migrations you made / whatever state the DB tables are in.

(similar to Ruby's sequel or ActiveRecord)

@thomasnal
Copy link
Contributor

Haven't seen it described above this way. Any idea how to get mapping automatically for free, having it inferred from migrations and database is welcome for the future.

I see quite a number of other practical hurdles than to be concerned about this one at the moment.

@imdrasil
Copy link
Owner

@z64 is right - this one is more about automatic schema generation. I have idea how to do this but for now there are a lot of important things to fix. So this will be added not as soon as I thought previously

@watzon
Copy link
Author

watzon commented Aug 31, 2017

I'm glad that this has at least been getting some attention. @z64 is right, but I understand that this isn't exactly top priority. It would definitely be a "nice to have" though.

@imdrasil
Copy link
Owner

Yeah. I keep this in mind and try make all new staff easy to migrate to this approach later, but for now main point is to make Jennifer useful and working tool for production purposes.

@AndiLavera
Copy link

Hey, just wanted to touch base and see if any progress was made on this front in the last 2 years. I just started using Jennifer with Amber.

@imdrasil
Copy link
Owner

imdrasil commented Jan 2, 2020

Hi. For that period of time this feature had low priority. The reason is that model declaration is inside of a model, so all fields and their types are inside of related file; database structure can be quickly loaded from structure.sql file. It is likely we will get it in 0.9.x or 0.10.0

@AndiLavera
Copy link

Completely Understand. Glad to hear it'll be coming sometime in the future and wasn't totally benched. Love your orm. Thanks!

@jamesst20
Copy link

+1 It would be awesome to have this feature, this is something I love in ActiveRecord (from Rails), it maintains a schema.rb always up to date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants