I'm interested in storing multiple values in a single column, rather than use the traditional many-to-many table:
class Beer
include DataMapper::Resource
property :id, Serial
property :name, String
property :containers, Integer # use bit arithmetic to store multiple values
validates_presence_of :name, :containers
end
class Container
include DataMapper::Resource
property :id, Serial # increment in powers of two?
property :name, String
property :volume, Integer
validates_presence_of :name, :volume
end
Containers:
ID Name Volume Unit
1 Growler 64 oz
2 Cowler 32 oz
4 Bomber 750 mL
8 Six-fifty 650 mL
16 4 pack 64 oz
32 6 pack 72 oz
Beers:
ID Name Containers
1 LSD 72
2 Düo 16
Is there an easy way to configure a DataMapper resource to increment serial values in powers of 2? I'm assuming that the association is going to be a challenge.