# Question on smart Relationships implementations

**URL:** <https://community.forestadmin.com/t/question-on-smart-relationships-implementations/1458>\
**Category:** Help me!\
**Created:** [December 14, 2020, 11:58am UTC](https://community.forestadmin.com/t/question-on-smart-relationships-implementations/1458 "2020-12-14T11:58:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/tom/32/677_2.png) [@Tom](https://community.forestadmin.com/u/Tom)\
**Post date:** [December 14, 2020, 11:58am UTC](https://community.forestadmin.com/t/question-on-smart-relationships-implementations/1458/1 "2020-12-14T11:58:41Z")

</div>

Hello 🙂  
i have some questions on the smart Relationships

I have Product document , each product have and embedded array of Object and i want to display them as a related Data .  
I declared the model for my embeddedObjects  
It raised a “Cannot read property ‘idField’ of undefined  
at ResourceSerializer.perform” error  
when trying to serialize it with Liana.ressourceSerializer  
It works fine if my related Data is a colllection Document

I’m probably ( certainly 😉 ) doing something wrong but cannot figure it out ☹

## Context

Please provide any relevant information about your setup.

- Package Version: 5.7
- Express Version: 4.16.3
- Sequelize Version:
- Database Dialect: mongodb js
- Database Version:
- Project Name: Panopli

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [December 14, 2020, 12:32pm UTC](https://community.forestadmin.com/t/question-on-smart-relationships-implementations/1458/2 "2020-12-14T12:32:06Z")

</div>

Hello Tom,

Can you share with us the relevant configuration on your model, and some example data?

Can you also tell me if your objects are documents (meaning that they have a unique id in mongoDB), or if they are only plain objects not managed by mongodb as documents?

Thank you

---

<div class="post-metadata">

**Author:** ![Tom](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/tom/32/677_2.png) [@Tom](https://community.forestadmin.com/u/Tom)\
**Post date:** [December 14, 2020, 1:26pm UTC](https://community.forestadmin.com/t/question-on-smart-relationships-implementations/1458/3 "2020-12-14T13:26:47Z")

</div>

Hello Guillaume 🙂  
My objects aren’t documents , they are only plain objects .

Here’s the model definition .

```javascript
const mongoose = require('mongoose')

const schema = mongoose.Schema({
  templateCode: String,
  side: {
    type: String,
    enums: ['front', 'back', 'left', 'right'],
  },
  previewURL: String,
  id: String,
}, { _id: false })

module.exports = schema

```

exemple Product data =\>

```javascript
{
  "_id": {
    "$oid": "5f5a0cebeb17470a730b185b"
  },

  "embroideryInfos": [
    {
      "previewUrl": "",
      "templateCode": "Template 1",
      "side": "front"
    },
    {
      "previewUrl": "",
      "templatecode": "Template 3",
      "side": "back"
    },
  ],
}

```

and here the code implementation

```javascript
const getEmbroiderys = async (req, res) => {
  try {
    const { productId } = req.params
    const product = await Products.findOne({ _id: ObjectID(productId) }).exec()
    const { embroideryInfos = [] } = product
    if (!embroideryInfos.length) {
    // do something
    }
    const embroidery = embroideryInfos.map((emb, index) => ({
      ...emb,
      id: `${productId}-${index}`,
    }))
    const serialized = await new Liana.ResourceSerializer(
      Liana,
      EmbroideryInfos,
      embroidery,
      null,
      { count: embroidery.length },
    ).perform()
    return res.status(200).send(serialized)
  } catch (e) {
    console.log('CATCHED', e)
    res.status(500).send(e)
  }
}

```

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [December 14, 2020, 2:41pm UTC](https://community.forestadmin.com/t/question-on-smart-relationships-implementations/1458/4 "2020-12-14T14:41:38Z")

</div>

Hello,

Thanks a lot for all the details.

Forest Admin natively supports embedded arrays of plain objects in schema definition. You don’t need to declare a smart relationship for it to work.

For this feature to work, you have to declare your array inside the parent object (don’t declare a separate schema for the embedded structure)

```javascript
// Product schema
const schema = mongoose.Schema({
  // [...]
  embroideryInfos: [{
    templateCode: String,
    side: {
      type: String,
      enums: ['front', 'back', 'left', 'right'],
    },
    previewURL: String,
    id: String,
  }]
})

```

---

<div class="post-metadata">

**Author:** ![Tom](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/tom/32/677_2.png) [@Tom](https://community.forestadmin.com/u/Tom)\
**Post date:** [December 14, 2020, 4:02pm UTC](https://community.forestadmin.com/t/question-on-smart-relationships-implementations/1458/5 "2020-12-14T16:02:01Z")

</div>

Ty Guillaume , i removed the smart routes , and added the object definition in the Product model. But then the popup “Your admin panel is currently being updated. The changes will take place in a few seconds…” runs and never resolves. I can still see my previous smart relationship in the related data . But no sign of the new one as related Data .

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [December 14, 2020, 4:11pm UTC](https://community.forestadmin.com/t/question-on-smart-relationships-implementations/1458/6 "2020-12-14T16:11:55Z")

</div>

Could you please share with me relevant parts of your model definition?

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [December 14, 2020, 4:23pm UTC](https://community.forestadmin.com/t/question-on-smart-relationships-implementations/1458/7 "2020-12-14T16:23:44Z")

</div>

Before investigating further, can you restart your server and check again? There was an issue on our side, causing some issues with the update of settings.

---

<div class="post-metadata">

**Author:** ![Tom](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/tom/32/677_2.png) [@Tom](https://community.forestadmin.com/u/Tom)\
**Post date:** [December 14, 2020, 4:34pm UTC](https://community.forestadmin.com/t/question-on-smart-relationships-implementations/1458/8 "2020-12-14T16:34:58Z")

</div>

The popup finally resolved 🙂 . I can see my related datas . Ty very much Guillaume
