# Specific table id

**URL:** <https://www.ruby-forum.com/t/specific-table-id/148944>\
**Category:** Rails\
**Created:** [September 18, 2008, 3:17pm UTC](https://www.ruby-forum.com/t/specific-table-id/148944 "2008-09-18T15:17:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [September 18, 2008, 3:17pm UTC](https://www.ruby-forum.com/t/specific-table-id/148944/1 "2008-09-18T15:17:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [September 19, 2008, 1:05am UTC](https://www.ruby-forum.com/t/specific-table-id/148944/2 "2008-09-19T01:05:29Z")

</div>

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.
