forest-express-mongoose icon indicating copy to clipboard operation
forest-express-mongoose copied to clipboard

Smart Fields not load on custom Related Data (with smart relationships)

Open GautierT opened this issue 8 years ago • 5 comments

Hi,

I have created multiple smart fields for a model. I then created a smart relationships to display this model on related data for an other model but here, i can see the columns for the smart fields but it's empty. The data are not loaded for this custom fields.

Thanks

GautierT avatar Sep 06 '17 09:09 GautierT

Hi @GautierT,

Please add a piece of code that represents you Smart Relationship getter implementation. Without it we cannot help you here.

arnaudbesnier avatar Sep 06 '17 09:09 arnaudbesnier

UPDATED

router.get('/forest/users/:userId/relationships/XX', Liana.ensureAuthenticated, async (req, res, next) => {
    debug('req.body : %O', req.body)
    debug('req.params : %O', req.params)
    debug('req.query : %O', req.query)

    try {

      const results = await Letters.paginate({
        user: req.params.userId,
        mode: 'test'
      }, {
        page: parseInt(req.query.page.number),
        limit: parseInt(req.query.page.size),
        sort: req.query.sort,
        populate: [{
          path: 'XX',
          select: '-__v'
        }, {
          path: 'XX',
          select: '-__v'
        }, {
          path: 'XX'
        }]
      })

      console.log('results.total : ', results.total)

      const serialized = await new Serializer(Liana, Letters, results.docs, {}, {
        count: results.total
        // Don't seem to work
      }).perform()

      debug('serialized : %O', serialized)

      return res.send({...serialized, meta : {count : results.total}})
    }
    catch (ex) {
      return next(ex)
    }

  })

GautierT avatar Sep 06 '17 09:09 GautierT

Sometimes (one over 10) the smart fields are fetch and visible. I think it's a problem in Ember. But i have no error in the console.

GautierT avatar Sep 06 '17 09:09 GautierT

The Smart Field values injection is not made here (it is not the Serializer that does that job in the current liana).

To make the magic happen we should do improve this and it would make your code work perfectly.

By the way, is it a special relationship you have between users and letters? I don't get why Forest does not detect this relationship automatically.

arnaudbesnier avatar Sep 06 '17 10:09 arnaudbesnier

Yes, it's a special one. Users does'n't contain an array of letters.

GautierT avatar Sep 06 '17 10:09 GautierT