开发者

Link a relation

开发者 https://www.devze.com 2023-03-21 21:43 出处:网络
I stuck in a situtaion and hope I will get a solution here. Situation is: A user when wants to join the club he/she has to provide their identification.Lets say a citizen card,passport,driving license

I stuck in a situtaion and hope I will get a solution here. Situation is: A user when wants to join the club he/she has to provide their identification.Lets say a citizen card,passport,driving license etc. If a user want to get ext开发者_运维技巧ra services from a club he/she has to provide other documents too like Bank Report,House property etc..

My problem is How to relate these documents .If I have to see the complete doucments of a user I should easily see all the documents given by a user.

Please help me.


I'll assume you have a user table, with a column called id which is a unique identifier for a particular user. Then you just need a table called documents with a column called document_id and a column called user_id (this one links to the id column in the user table).

Then you just do a query like so:

SELECT my_column_names FROM user 
LEFT OUTER JOIN documents ON documents.user_id = user.id 
WHERE some_condition

You'll probably want to store some information about the documents in the documents table, as well as either storing the document itself as a BLOB or just storing a filepath to where the document is saved on your file system; but that's really not part of the question.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号