Each association
should be an array containing the database field name (the attribute on the model) and the
parameter name (the attribute on the value object). To assign multiple attributes, you group
them as an array of arrays. The order in which you define your attributes within your value
object is the order in which these values will be set.
Some examples should clear things up a little bit. Let??™s assume we have an accounts table
with an account_username and account_password field and a Userinfo value object with username
and password attributes. We can use the mapping option to tell Active Record where to look for
our data in the aggregated objects. Here, we create an aggregation, first with just the username
field, and then with both username and password fields:
composed_of :userinfo, :mapping => ["account_username","username"]
composed_of :userinfo, :mapping => [["account_username","username"],
["account_password", "password"]]
Step 2: Defining Your Value Object
For the most part, defining your value object is just like defining any other standard Ruby class.
Pages:
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260