[技術討論] 問一下program logic


呢個係backend admin 加user嘅畫面
form submit後,backend會check user account 同email address 有無其他人使用了, 有就feedback 返要入過。


呢個係修改existing user account 畫面,user嘅info係從db fetch 入去張html form

問題係,因准許user account及email 可修改的,咁樣唔改直接submit, 係會話你(同上)user account 同email address 有無其他人使用了。如果唔check, user可以改了相同的user name 或email

呢part 嘅logic 應該要點處理?
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

你有冇用framework? 呢d麻煩野通常orm handle
如果diy solution,  唔好check duplicate, 直接隊比database,
如果有exception,  呢個時候先check有冇duplicate

TOP

Edit時exclude返自己個record, 例如你用user_id做primary key:

SELECT user_name FROM user WHERE user_name = 'user4' AND user_id <> '4';

有野return即係有duplicate.

TOP

In the User Controller Edit method add a duplicated check.
If exist then exclude the field in the save, otherwise override the record.

TOP

edit 果陣  check 埋 user id

TOP

已解決了。
我做法係check當前的操作是edit account定係add new account來判斷

via HKEPC Reader for Android

TOP

回覆 6# takayo72


    咁race condition 呢

TOP

冇PK, 例如member id ?

TOP

應該俾個uid 佢係不變。

TOP