How active record is automatically setting up the autoincremental value of ID?
        Posted  
        
            by piemesons
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by piemesons
        
        
        
        Published on 2010-04-21T07:28:01Z
        Indexed on 
            2010/04/21
            7:33 UTC
        
        
        Read the original article
        Hit count: 378
        
Here this is what we are doing:--
an_order = Order.new 
an_order.name   = "Dave Thomas" 
an_order.email  = "[email protected]" 
an_order.address = "123 Main St" 
an_order.pay_type = "check" 
an_order.save
Now it will insert a new row in orders table right. I m having a ID column in that table. Now suppose after inserting this record the value of the ID corresponding to this record is 100. Now how this 100 value came to know?
Does the previous value of ID ie 99 (Suppose) is stored somewhere in some variable/file in the ORM layer
or
before inserting this value a query was fired to know about the last inserted value or
database is itself doing that or
anything else???
© Stack Overflow or respective owner