Parse server already has a _User table with objectid and username. objectid is the primary key in the _User table. I want to link my PaymentHistory table by using the objectid in the _User table as the foreign key in my PaymentHistory table. How do I change my curl command to create the foreign key?
I know there is a relations section in the document: REST API Guide | Parse
But the document is not very clear and I still don’t know how to use it.
I understand parse server works better with MongoDB, but I cannot install MongoDB in my system. So, I have to use Postgres. I just hope there is a way to create a foreign key relation via curl. Thanks
@uzaysan Thank you very much! Could I ask some follow-up questions? Is there a way to impose a “unique” requirement for a particular column? For example, if I have a phone_number column, I want every number in the phone_number column be a unique number. Is there way to specify this? Moreover, is there a way to specify string length in the “String” type? Thanks
For unique property, you can create a unique index for phone_number column. I create my indexes on database directly. So I dont know ıf you can define a unique index from parse schema but you can try this.
I’m not sure if unique: true will work. If it doesnt work, You can download mongo compass. And create indexes visually.
I dont think this is possible. But you can define a beforeSave trigger for that.
Parse.Cloud.beforeSave("ClassName", request => {
const object = {request};
if (object.get('phone_number').length > 10) {
throw new Error('phone_number field must be 10 digits');
}
});
However, it looks like the “payer” column does not have any indication that it is a foreign key (see the screenshot). Is this correct? How do I check whether the PaymentHistory table is working using the curl command?
If I want to use curl post to test this table, the “payer” value should be objectid in the _User table, right? Also, how do I generate “Date” value using the curl command to populate the paymentTime column?
Thats normal. Pointers are stored in text format on database with Classname$ObjectId format. If you set a user pointer for that field, It will look like _User$Yght75scF5 where Yght75scF5 is objectId of the user.
fields: {paymentTime : {type: "Date", required: false}}
This should work.
@uzaysan Thanks. This works. But my question is: could I use “curl -X POST” to add a row in this table? For example, in swift, I can add one row by using
let user = try? User.current?toPointer()
let payment = PaymentHistory(payer: user, paymentMethod: "credit card", paymentTime: Date(), paymentAmount: 100, paymentStatus: true)
payment.save {}
Is there an equivalent curl -X POST command? Thanks
@uzaysan Thanks. Is there an equivalent way to add payer: user pointer using “curl -X POST”? I am just curious:) Also, some people said I should not add columns to _User table. Is this true? If I am not allowed the add columns to the _User table, how could I add a profile image for a user? Create a new table and reference to the _User table?
@uzaysan Thank you very much! It works. The only small difference is you use “__type”: “Pointer” and I used “type”: “Pointer”. It seems “type” works, but I did not try “__type”. So, I don’t know whether " “__type” will work.
Also, is there a bytea data type for me to save image data?
I think your answers should be part of the official document.
@uzaysan Thanks for your answers. But where does parse server save the image files after I upload them? Does parse save them in a particular folder? Do I need to configure file storage service, like AWS S3?
@uzaysan Are you sure the uploaded file is saved in the database? According to the document you sent to me. After a user uploaded a file successfully, the response is:
It seems that the response includes a url pointing to the file. So, I am wondering whether the file is indeed in the database.
I’m sure. İf you don’t specify a file adapter, file is saved to database. That url you see is parse server public url you defined in parse server constructor. When you don’t have a file adapter, parse proxies the file