Closed alimi closed 4 years ago
You could have Magma call it in load_models or whatnot, after the models themselves have loaded, this would be in line with #129.
Cool, that makes sense. I added it to the end of Magma::Project#load_project
so the db attributes get set after the Ruby attributes. https://github.com/mountetna/magma/pull/132/commits/bc5c12734a573d65a3d95661430b363ee68e1ef3
@notmarkmiranda heads up I added a test here for loading link models from the attributes table.
I had this test before https://github.com/mountetna/magma/pull/134, but it was just using link_model
instead of link_model_name
. It wasn't too hard to resurrect 🧟♂️
@graft I have a couple of questions
It seems like this is okay, since we will have the choice of when we replace the Ruby attributes with the db attribute. We might want to write some attribute-auditing code to identify discrepancies before we unhook the models fully.
I don't know what I meant any more. I think I may have been confused about the type being included on updates, but it is only included in the intial insert.
This builds on https://github.com/mountetna/magma/pull/123.
Magma::Model.load_attributes
pulls a model's attributes from the database and defines them on the model using the newly addedtype
column.With
Magma::Model.load_attributes
, we'll no longer need to load attribute options when initializingMagma::Attribute
objects. This will also give us a little performance boost since we'll get all a model's attributes in one database query. However, we'll no longer be able to merge attributes defined both in Ruby and the database.This PR also makes more
Magma::Attribute
options editable, butmatch
is still not supported. It also makesloader
andlink_model
editable which might not be desired. I can remove it--just lemme know 😄.I'm also not sure where we should call
Magma::Model.load_attributes
. I could see make adding it explicitly in models likeso the database attributes take precedence over anything defined in the Ruby files. Alternatively, I could see calling it after the definition to guarantee it's always called.
But this would let Ruby attribute definitions override the database definitions. It might not be a big deal since we want to move away from Ruby definitions anyways. I'm curious on what y'all think.
/cc @notmarkmiranda @graft