Prev | Current Page 177 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"

For the remainder
of this section, let??™s say we??™re writing an application to maintain the books for a cooperative
of farmers who raise cattle.
CHAPTER 4 ?–  CORE FEATURES OF ACTIVE RECORD 69
Every farmer needs to keep track of a lot of cows, and all farmers sell their cows??™ milk to various
resellers at their own unique prices. Finally, each reseller and farmer has an address, because
the reseller needs to know where to send the checks, and the farmer needs to know where to send
the milk. The basics of the tables are laid out as follows (we are using basic migrations for these
definitions, for more on migrations refer to the previous chapter):
create table :cows do |t|
t.column :name, :string
t.column :farmer_id, :integer
end
create table :farmer do |t|
t.column :name, :string
t.column :address, :string
end
create table :reseller do |t|
t.column :name, :string
t.column :address, :string
end
create table :farmers_resellers do |t|
t.column :resller_id, :integer
t.column :farmer_id, :integer
end
create table :distributors do |t|
t.


Pages:
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189