I ran across this issue when dealing with related documents with a Mongo DB backend. I have a models.json file that looks contains something similar to:
{
"service": {
"properties": {
"slug": {
"type": "String"
},
"title": {
"type": "String"
},
"link": {
"type": "String"
},
"subtitle": {
"type": "String"
},
"intro": {
"type": "String"
},
"content": {
"type": "String"
},
"icon": {
"type": "Object"
},
"image": {
"type": "Object"
}
},
"public": true,
"dataSource": "db"
},
"serviceCategory": {
"options": {
"relations":{
"services": {
"model": "service",
"type": "hasMany"
}
}
},
"properties": {
"title": {
"type": "String"
},
"tagline": {
"type": "String"
},
"subtitle": {
"type": "String"
},
"intro": {
"type": "String"
},
"content": {
"type": "String"
},
"image": {
"type": "object"
}
},
"public": true,
"dataSource": "db",
"plural": "serviceCategories"
}
}
When retrieving services with a request similar to /api/serviceCategories/<id>/services I get back objects that have a serviceCategoryId field with the string equivalent of a Mongo ID. If a change is made to one of those retrieved documents and it is updated via a PUT request, what was an ObjectId is replaced with a string and Mongo loses the relationship. (i.e. the document is no longer retrievable via the original request.)
In a conversation over IRC rfeng suggested that creating a custom ObjectId type for Mongo might be a solution to this issue and that I should file a bug here for direction on how to go about that. Thinking about the issue, I'm wondering if this should be handled when the initial relationship is defined, that appears to be where the foreign key field is implicitly created. In either event, an ObjectId type is likely a requirement.
I ran across this issue when dealing with related documents with a Mongo DB backend. I have a models.json file that looks contains something similar to:
When retrieving services with a request similar to
/api/serviceCategories/<id>/servicesI get back objects that have aserviceCategoryIdfield with the string equivalent of a Mongo ID. If a change is made to one of those retrieved documents and it is updated via a PUT request, what was an ObjectId is replaced with a string and Mongo loses the relationship. (i.e. the document is no longer retrievable via the original request.)In a conversation over IRC rfeng suggested that creating a custom ObjectId type for Mongo might be a solution to this issue and that I should file a bug here for direction on how to go about that. Thinking about the issue, I'm wondering if this should be handled when the initial relationship is defined, that appears to be where the foreign key field is implicitly created. In either event, an ObjectId type is likely a requirement.