4 Replies Latest reply on Jan 5, 2013 10:46 PM by Robert Toellner

    How can I edit a Model after being created?

      I created a model and I already have some code on it. If I want to add a field (property) or rename it. How can I do it without deleting the whole folder? Where is that model defined itself?

        • Re: How can I edit a Model after being created?
          Derek Warren

          If you are using the PropertyBag type (seen in your model.rb file) you can add a property to the model without requiring any new code. You would simply reference the property like any other property. (Model.property)

          1 of 1 people found this helpful
            • Re: How can I edit a Model after being created?
              Mark Nongkhlaw

              What about removing a property?

              • Re: How can I edit a Model after being created?



                When I define a model I have to set the properties:


                Model Product: SKU,Image,Name


                If later on I decide that I would like to move the "SKU" parameter to another model or just change the name to "code". Where this information is stored when is created?
                I understand that if I change something in the model then I will have to apply some changes in edit.erb, show.erb, new.erb and probably in the controller, but what I want to know is this:


                the parameters passed when defining a new model are only used for generating the CRUD interface and then this data is lost, so there is not place to change this right? and that only works when fixed schema is used.


                Can you please confirm?



                  • Re: How can I edit a Model after being created?



                    this kind of stumped me for a bit as well as there is some 'magic' involved. But, it appears there are templates and a set of scripts to generate the files ( scaffolding like ) which create those various .erb files. The attributes you type in are simply used by those scripts to fill in the templates. You can always rerun the model generation later but it will overwrite the existing files. If you need to add/remove an attribute after creation, you'll need to manually edit the appropriate files - and of course the source adapter side of things. The generator only creates a PropertyBag definition which is the default. For a FixedSchema definition, you have to edit those files manually afterwards anyway and specify the attributes manually - I assume this will be a choice later on when creating a model.


                    You can find the scripts within the rhodes gem e.g. ..\ruby\gems\1.9.1\gems\rhodes-\res\generators