Prev | Current Page 455 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"

However, if you wanted to perform a migration of
similar or identical models between two databases, it would be useful to put each of your
classes inside of a module. For example, assume you have User and Email databases on both
servers and you wish to copy a user from one database to the other:
Module LocalDb
class User < LocalDatabase
belongs_to :customer
has_on :email
end
class Email < LocalDatabase
belongs_to :user
end
end
Module RemoteDb
class User < RemoteDatabase
belongs_to :customer
has_on :email
end
class Email < RemoteDatabase
belongs_to :user
end
end
You can then reference the remote User model with RemoteDb::User and the local User
model with LocalDb::User.
CHAPTER 8 ?–  ACTIVE RECORD AND THE REAL WORLD 203
user = RemoteDb::User.find_by_name('Chad Pytel', :include => [:email], :limit => 1)
new_user = LocalDb::User.new user.attributes
new_user.email = LocalDb::Email.new user.email.attributes
new_user.save
How Do I Handle Internationalization and Localization?
Active Record does not include default support for internationalization or localization.


Pages:
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467