ActiveRecord works on the principle that each table has a single primary key column that has no significance within the application domain. That's (partly) why you don't have to define the id
column in your create_table
migrations. The column name (and type) can be changed, largely to accommodate legacy schemas, and multiple-column primary keys are hard to implement at all.
At the point where you start to ascribe a domain significance to the id, you're starting to break the convention and I'd strongly advise that you create another field/property/member-variable/column/what-have-you to hold that information. Leave the id to being a key.
In the use-case you describe, there's no reason that your controller shouldn't identify the special case where params[:id] == '0'
and deal with it appropriately, switching to the "project part", which you identify in some way other than by id
. Since you probably want each project to start from 0, I'd guess you'd add something like seq
and use that instead of id
in your routes, that way your params keys make more sense. Keep the current highest seq
value in the project, so it knows what number to assign when a new part is created. Deletions and insertions (assuming sequence matters) are entirely up to you...