This project is archived and is in readonly mode.
Single Table Inherited model generator
Reported by Fabien Jakimowicz | May 24th, 2009 @ 01:47 AM | in 3.0.2
If I have to generate a model (and its associated unit test) which inherited from another model (sti), i have to use model generator with two options and to manually modify generated model.
This generator create a simple class which inherit from its
parent:
script/generate sti_model car vehicule
will generate the following model:
class Car < Vehicule
end
Patch contains both documentation and test. It applies cleanly on master and 2-3-stable branches.
Comments and changes to this ticket
-
Ian Terrell May 24th, 2009 @ 01:59 AM
I like this. I'm constantly forgetting to turn off the migration and the fixture in the regular model generator.
-
Michael Koziarski May 26th, 2009 @ 11:48 AM
- Milestone cleared.
- Assigned user set to Michael Koziarski
This looks good to me, but I think the names should be:
script/generate model_subclass Foo Bar
And the usage should name those things Subclass and Parent
Make those changes, upload the patch and I think we're good to go!
Nice simple enhancement, good work.
-
Fabien Jakimowicz May 26th, 2009 @ 12:52 PM
I renamed it to model_subclass and modified documentation and tests.
Thanks !
-
Repository May 27th, 2009 @ 12:19 PM
- State changed from new to committed
(from [2cb60abfecbad78046b0afde156c72a9ae766cf0]) Add an model_subclass generator.
This generator creates a new model as a subclass of an existing model and the unit test for that model. Lets users avoid having to manually delete the fixtures and migration or remember to pass those arguments.
[#2702 state:committed]
Signed-off-by: Michael Koziarski michael@koziarski.com
http://github.com/rails/rails/commit/2cb60abfecbad78046b0afde156c72... -
José Valim June 27th, 2009 @ 03:00 PM
Fabien e Koz,
I'm reworking on generators for GSoC. I'm currently planning to move model_subclass out and add a parent option:
script/generate model Car --parent=Vehicule
The main reason is, everyone can extend the model generator to add new behavior. If we have both model_subclass and model, plugin developers will have to extend both.
When a parent option is given, migration is not generated.
What do you think?
-
Michael Koziarski June 28th, 2009 @ 01:01 AM
Sounds good to me, so long as the result is the same a --parent option
could be just as nice (if not nicer :)) -
José Valim June 28th, 2009 @ 02:55 PM
Koz,
The good think is that you can even use it in scaffold, since it will only delegate to the model generator:
script/generate scaffold Car --parent=Vehicule
It creates everything, except the migration.
And how the results could be even nicer? I'm listening! :)
Finally, do you think we need to add a deprecation warning to model_subclass? In theory, it was not released and it's not on the 2.3 stable as well.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 2702 Single Table Inherited model generator [#2702 state:committed]