Adding references does not work with record creation

Expected behavior

Search and add a referenced document upon creating a new record.

Actual behavior

The referenced document could be searched but the “Add” button was automatically disabled. It was working when a new document was attempted to be added into an existing record. Does it have something to do with the fact that the reference field is a smart field?

Failure Logs

None

Context

Database: MongoDB

Hi @linsze

Could you make a loom of the behavior you are experiencing (Or if not, more details of the procedure to reproduce the issue)? From what I can read I’m not able to reproduce.

If there is any, could you also provide your browser console log info so I can investigate on what is happening.

Thanks in advance.

Hi, it seems to be working now. Thanks for your time.

1 Like

Hi, sorry about this. I tested with an existing record and it was working but it didn’t work with a new record. Unfortunately, there isn’t any console log info for me to inspect what’s happening. This issue can be reproduced by simply creating a new record in a collection and attempting to add a referenced document.

This is the attempt with a new record. The “Add” button has been automatically disabled.

This is the attempt with an existing record. The “Add” button is now enabled.

Super, thanks for the update.

I’m able to reproduce this issue as well. I’ll open a ticket for this issue to be fixed. We’ll let you know once it is released.

Sorry for the inconvenience.

EDIT: The fix has been found and is currently under review.

Great to hear that. Thanks a lot!

@linsze

The fix was just released and after a quick check, I’m not able to reproduce your issue anymore (You may need to refresh your browser).

Let me know if that helps :pray:

Yes, it’s been resolved now. Thank you so much!

2 Likes

Hi, a follow-up question on this, when a new record is created, I realized that the attributes are only the details without the relationship fields. Is there a way I can possibly get those fields?

Hi

I’m not sure to fully get your question, you should be able to see the new record with the related data once added.
Could you be more precise of the behavior you want/are not getting?

Thanks in advance

Hi, sorry for the confusion. I would like to overwrite the default route of creating a new record.

When I obtained the attributes through this method, I could only obtain the fields associated with it but not the relationship fields.

On this post service, you’ll not get the related data - this is not the service that handle that part. You could potentially use the Record(s)Getter here to get the associated records from your DB in this service if that’s what you really need.

If you want to extends the behavior of adding/getting/… related data, you may need to look here.
There are a few routes added to manage your relationships CRUD.

If you are more specific about your need, I might be able to provide a code sample of such a route being override.

Let me know if that helps.

I see. My approach here is to use the related data to query for other information before inserting into the database. If I use RecordGetter in the route itself, it seems like the record does not exist at that point of time. Do you have any suggestions on this?

Yes. In fact, my direction was not the best, since you are right, the record is not created.

On creation, req.body.data.relationships should contains the informations you need, as you can see here

image

req.body.data.attributes will contains the main “details” of the records, while req.body.data.relationships will contains the related data associated to your record during the creation.

In your console.log, replacing attributes with relationships should give you your related data.

Hope that helps.

Yes, that definitely helps. Thank you so much!