I tried to save records with specific ids, but without any success …
@date = Time.now.to_date
tour_id = (@date.year.to_s + @date.month.to_s +
@tour = Tour.new(:id => tour_id, :scheduled_on => @date, :carts =>
id should be something like 20080918 (there could be only one record
but it’s stil using an incremental id… 1
(I am using sqlite3 dev…)
thanks for any help
The Rails convension for database table ids is that they have
absolutely no meaning in and of themselves.
So the ‘Rails Way’ to do this is to have a separate column (maybe
called date_as_int) to store this. Then put a unique index on the
column and have validates_uniquness_of :date_as_int in the database.
If this is impossible (and I can’t think why it could be) then you
have to alter your database table to remove the auto-increment from
the id column. (A standard Rails migration automatically adds an id
column and sets it to auto increment.) I can pretty much guarantee
that if you try this you will give yourself all sorts of headaches in
both the short-term and the long term. You really should follow the
Rails convension and store this information in a separate column.