简体   繁体   中英

Rails inheritance and migrations

I am new to rails and I am trying to complete a little project for my undergrad. The application will have a REST api, and I want every api resource to have an api_guid attribute.

Is there a way to tell this to the "rails generate model" command line? Like, if belongs to super class ApiResource include api_guid cloumn.

Whats the best way to store the guid on mysql? I am currently saving it as a string.

Thank in advance,

There is a --parent option for rails generate model (just run it without arguments to get the documentation), but that seems to want to give you single table inheritance (basically Rails will store all of your data in the same table which has the name of the superclass and will use the type field to distinguish between the subclasses).

Also we use GUIDs as strings in production and that works fine for us.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM