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 + @date.day.to_s).to_i @tour = Tour.new(:id => tour_id, :scheduled_on => @date, :carts => @cart_works) @tour.save! id should be something like 20080918 (there could be only one record per day...) but it''s stil using an incremental id... 1 (I am using sqlite3 dev...) thanks for any help --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. Erwin wrote:> 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 + > @date.day.to_s).to_i > > @tour = Tour.new(:id => tour_id, :scheduled_on => @date, :carts => > @cart_works) > @tour.save! > > id should be something like 20080918 (there could be only one record > per day...) > > but it''s stil using an incremental id... 1 > > (I am using sqlite3 dev...) > > thanks for any help--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---