Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Single Table Inherited model generator

#2702

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.

Reported by Fabien Jakimowicz · May 24th, 2009 @ 01:47 AM

State: committed
Milestone: 3.0.2
Assigned to: Michael Koziarski Michael Koziarski
Importance: none

Activity

  1. Ian Terrell
    Ian Terrell

    I like this. I'm constantly forgetting to turn off the migration and the fixture in the regular model generator.

    May 24th, 2009 @ 01:59 AM

  2. Michael Koziarski
    Michael Koziarski
    • 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.

    May 26th, 2009 @ 11:48 AM

  3. Fabien Jakimowicz
    Fabien Jakimowicz

    I renamed it to model_subclass and modified documentation and tests.

    Thanks !

    May 26th, 2009 @ 12:52 PM

  4. Repository
    Repository
    • 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 Single Table Inherited model generator state:committed]

    Signed-off-by: Michael Koziarski michael@koziarski.com
    http://github.com/rails/rails/commit/2cb60abfecbad78046b0afde156c72...

    May 27th, 2009 @ 12:19 PM

  5. José Valim
    José Valim

    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?

    June 27th, 2009 @ 03:00 PM

  6. Michael Koziarski
    Michael Koziarski

    Sounds good to me, so long as the result is the same a --parent option
    could be just as nice (if not nicer :))

    June 28th, 2009 @ 01:01 AM

  7. José Valim
    José Valim

    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.

    June 28th, 2009 @ 02:55 PM

  8. Jeremy Kemper
  9. bingbing