Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
best way to ignore deleted users from all queries?
  • (Note: I wasn't sure if this topic was most appropriate in the General or ORM or Auth forum. Please move if ORM or Auth is better!) I'm hoping to pick the brains of the FuelPHP community. I have a solution to this issue, but I'm not sure if it's the best one. My application will allow users to delete their accounts, but we will retain select data. From the users table, we're keeping id, username, and group. I'm using simpleauth and simplegroup for authentication and group management. When the user deletes their account, they are added to the "deleted" group (-1). I want to completely ignore all data from deleted users in every query in my application. What I've done is extended the find method in my user model like so :
    public static function find( $id = null, array $options = array() ) 
    {
      $not_deleted = array(
        'where' => array( array( 'group', '>', 0 ) )
      );
    
      if ( ! empty( $options['where'] ) ) // don't overwrite existing where options
        $options['where'] = array_merge( $options['where'], $not_deleted['where'] );
      else
        $options = array_merge( $options, $not_deleted );
    
      return parent::find( $id, $options );
    } 
    

    So I'm adding a where condition that will filter out any users in the deleted group. So far this works fine, but I'm concerned it won't won't in all situations or that there's a better way. What do you guys think? How might you approach this issue? Thanks very much!
  • PS - This wasn't exactly suited to my needs since I do want to delete most of the user's data, but there's a nice option for "soft deleting" data with this soft delete package : https://github.com/limboo/orm-softdelete In case it's relevant to anyone who comes across this thread. :)
  • Another option would be to move these users to a "deleted users" table, that way it doesn't complicate any of your normal queries.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion