2017-01-19 47 views
0

我爲Extent aredux-ORM模型看起來像:自舉許多與終極版-ORM許多關係

const { string, number, arrayOf, oneOfType, instanceOf } = PropTypes 

export default class Extent extends ValidatingModel {} 

Extent.fields = { 
    xmin: attr(), 
    ymin: attr(), 
    xmax: attr(), 
    ymax: attr(), 
    zoomlevel: attr(), 
    tooltip: attr(), 
    tooltipDelay: attr(), 
    layers: many('Layer', 'extents'), 
    users: fk('User', 'extents') 
} 

Extent.propTypes = { 
    xmin: number, 
    ymin: number, 
    xmax: number, 
    ymax: number, 
    zoomlevel: number, 
    tooltip: string, 
    tooltipdelay: number, 
    layers: oneOfType([ 
    arrayOf(number), 
    arrayOf(
     instanceOf(Layer) 
    ) 
    ]) 
} 

Extent.modelName = 'Extent' 

我有相關Layer模型的定義是這樣的:

const { 
    string, 
    number, 
    bool, 
    any, 
    oneOfType, 
    instanceOf 
} = PropTypes 

export default class Layer extends ValidatingModel {} 

Layer.fields = { 
    objtype: fk('Bo', 'layers'), 
    layertype: attr(), 
    label: attr(), 
    layertypevalue: attr(), 
    geometrytype: attr(), 
    opacity: attr(), 
    token: attr(), 
    url: attr(), 
    readonly: attr(), 
    isFetching: attr(), 
    'default': fk('LayerConfiguration'), 
    status: attr(), 
    enabled: fk('LayerConfiguration', 'enabledLayers'), 
    highlighted: fk('LayerConfiguration', 'highlightedLayers'), 
    disabled: fk('LayerConfiguration', 'disabledLayers'), 
    filtered: fk('LayerConfiguration', 'filteredLayers'), 
    editing: fk('LayerConfiguration', 'editingLayers') 
} 

Layer.options = { 
    idAttribute: 'layerId' 
} 

我引導他們的數據是這樣的:

const victoriaExtent = Extent.create({ 
    xmin: 144.776008, 
    ymin: -37.8458979, 
    xmax: 145.101998, 
    ymax: -37.6845001, 
    zoom: 15, 
    tooltip: 'Victoria', 
    tooltipDelay: 0 
}) 

const transformer = Layer.create({ 
    layerId: 1, 
    label: 'Transformer', 
    objtype: 'EQUI', 
    layertype: 'PLANPLANT', 
    layertypevalue: '0001', 
    geometrytype: 'Point', 
    opacity: 1, 
    token: null, 
    url: null, 
    readonly: false, 
    extents: [ victoriaExtent ], 
    status: 'default', 
    isFetching: false, 
    'default': null, 
    enabled: transformerEnabledConfig, 
    highlighted: highlightPointConfig, 
    disabled: transformerEnabledConfig, 
    filtered: transformerEnabledConfig, 
    editing: editingPointConfig 
}) 

在狀態,我發現這種關係沒有被填充,儘管它顯示在Layer狀態下0123'有SessionBoundModel。數據不填充關係模型ExtentsLayer

此外,當我訪問擴展區時,我發現extent.layers屬性爲undefined

回答

0

我不明白爲什麼(但),但我發現接近另一方(這是如何定義的)的關係會產生成果。我改變了自舉的樣子:

const victoriaExtent = Extent.create({ 
    xmin: 144.776008, 
    ymin: -37.8458979, 
    xmax: 145.101998, 
    ymax: -37.6845001, 
    zoom: 15, 
    tooltip: 'Victoria', 
    tooltipDelay: 0, 
    user: spilli, 
    layers: [ 
    transformer 
    ] 
}) 

有了這樣的定義,當我用下面的語句在我layers選擇:

const layers = layerGroup.layers.toModelArray().map(layer => { 
     const obj2 = layer.ref 
     let enabled = layer.enabled 
     let extents 

     if (enabled && enabled.icon) { 
     const enabledRef = enabled.ref 
     const icon = enabled.icon.ref 
     enabled = Object.assign({}, enabledRef, { icon }) 
     } 

     if (layer.extents) { 
     extents = layer.extents.toRefArray() 
     } 

     return Object.assign({}, obj2, { enabled, extents }) 
    })