As you can see, we are explicitly setting the ID
of the object. Then, because our object already has a value in the id attribute, Active Record
will not attempt to generate a new one.
The second way to implement this functionality is by using an abstract Base class. This
abstract class will provide the same functionality as the previous module, by providing
a before_create method:
class UUIDKeyClass < ActiveRecord::Base
self.abstract_class = true
def before_create
self.id = UUID.timestamp_create().to_s
end
end
Next, rather than having your Active Record class extend ActiveRecord::Base, your class
will extend the class UUIDKeyClass:
class User < UUIDKeyClass
# your additional model code
end
Can I Use Active Record in aMultithreaded Program?
Active Record can work inside of a multithreaded program. However, with all the Active Record
adapters except those for PostgreSQL and Oracle, deadlocks can occur, because their underlying
APIs do not use nonblocking I/O.
How Do I Ensure Proper Handling of Decimal Numbers?
Historically, Active Record, like many libraries, has had issues with ensuring that decimal values,
such as currency, are handled correctly.
Pages:
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472