trongate / trongate-framework

The Trongate PHP framework
https://trongate.io
Other
1.12k stars 100 forks source link

Improvement on update function in Model #152

Closed monxian closed 1 year ago

monxian commented 1 year ago

This improvement for for the update function allows for any column to be used for the update. It takes $update_id, $data, table name, and column name. Table name and column name can be omitted and the function defaults to table id with the $update_id being the value. However, Table name is required when using the column field.

trongate commented 1 year ago

I'm an idiot! In my previous comment, I advised extending the 'update' function by adding an optional fourth field. This was poor advice. The reason why it was poor advice is because in instances where you perform an update based on something that's not an ID then the $update_id variable become a problem. I apologise. I completely messed this up.

Again... my advice was duff.

How about if we had a function called 'update_where'?

This is probably close to or even identical to your original suggestion.

So, perhaps you could have...

$this->model->update_where($column, $value, $data, $table_name (optional));

Would something like that work?

monxian commented 1 year ago

Really? I thought addressed this with an if condition. If there is no column argument then it falls back to updating by id.

No problem here is the updated update_where function

On Sun, Sep 3, 2023, 12:13 PM Trongate @.***> wrote:

I'm an idiot! In my previous comment, I advised extending the 'update' function by adding an optional fourth field. This was poor advice. The reason why it was poor advice is because in instances where you perform an update based on something that's not an ID then the $update_id variable become a problem. I apologise. I completely messed this up.

Again... my advice was duff.

How about if we had a function called 'update_where'?

This is probably close to or even identical to your original suggestion.

So, perhaps you could have...

$this->model->update_where($column, $value, $data, $table_name (optional));

Would something like that work?

— Reply to this email directly, view it on GitHub https://github.com/trongate/trongate-framework/pull/152#issuecomment-1704344382, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABVLIOD6PCUFVCMJTECCZ63XYSUDJANCNFSM6AAAAAA4ITVSWU . You are receiving this because you authored the thread.Message ID: @.***>