Retsly/data-dictionary — pull request #8 by lvivier (2014-12-03 00:11:01+00:00)
Title: Repeating elements

This issue is about how to represent repeating elements in this schema and ultimately in Mongoose.

## "Repeating elements"?

The definition of a "repeating element" is given in the MetaDefinitions table of the Data Dictionary:

> "[type]" Indicates that a field may be repeated and will include a defining string that indicates the instance of the repeated element. Such that Room[type]Features becomes RoomKitchenFeatures and refers to the Features of the Kitchen.

Here are some of the Room repeating elements from the Property resource:

> ### RoomType *String List, Multi*
This field is a list of the types used in the rooms repeating elements. The Type is a list of possible room types. i.e. Bedroom, Bathroom, Living Room, Workshop, etc. Each selected are expected to appear as the "[type]" in the related rooms fields. Note that Garage or Basement should not be added as a room type and are represented by the ParkingFeatures and Basement fields respectively.

> ### Room[type]Area *Number*
[type] This field is a repeating element for each type of room selected in the RoomType field. For every enumeration selected in the RoomType field, add an iteration of this field replacing [type] with the value from RoomType. The total area of the room. Use the RoomAreaUnits for the units of measurement used in this field.

I think what this means is that a document with repeating room elements would have an object representation something like this:

```js
{
/* ... */
RoomType: ['Kitchen', 'MasterBathroom'],
RoomKitchenArea: 150,
RoomKitchenAreaUnits: 'Square Feet',
RoomKitchenAreaSource: 'Agent',
RoomKitchenDimensions: '20 x 7.5',
RoomKitchenLength: 20,
RoomKitchenWidth: 7.5,
RoomKitchenLengthWidthUnits: 'Feet',
RoomKitchenLengthWidthSource: 'Agent',
RoomKitchenLevel: 'Main',
RoomKitchenFeatures: ['Double Sink', 'Stainless Steel Appliances'],
RoomKitchenDescription: '...',
RoomMasterBathroomArea: 40,
RoomMasterBathroomAreaUnits: 'Square Feet',
RoomMasterBathroomAreaSource: 'Agent',
RoomMasterBathroomDimensions: '8 x 5',
RoomMasterBathroomLength: 8,
RoomMasterBathroomWidth: 5,
RoomMasterBathroomLengthWidthUnits: 'Feet',
RoomMasterBathroomLengthWidthSource: 'Agent',
RoomMasterBathroomLevel: 'Main',
RoomMasterBathroomFeatures: ['Glass Enclosed Shower', 'Heated Autonomous Robot Bidet', 'Guest WiFi'],
RoomMasterBathroomDescription: '...'
/* ... */
}
```

Unfortunately I don't think we can represent this kind of free-form-ish schema without modifying Mongoose internals, which assumes a consistent schema for all instances of a type (not unreasonable—that's the idea of types).

Alternately, we can generate a schema that already includes all of the fields for each enumeration of each RepeatingElement, but this is a really large number of optional elements.

## TODO

- [ ] Figure out what to do
- [ ] Do it