Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong type in Fuel_user_model::delete() #544

Open
marcus-at-localhost opened this issue Sep 13, 2019 · 5 comments
Open

Wrong type in Fuel_user_model::delete() #544

marcus-at-localhost opened this issue Sep 13, 2019 · 5 comments

Comments

@marcus-at-localhost
Copy link
Contributor

Consider this piece of code in a migration file, throwing an error at $user->delete()

	public function down()
	{
		$user = $this->fuel->users->model()->find_one(['user_name' => 'stm']);
		$user->delete();
		// this works
		//$this->fuel->users->model()->delete(['user_name' => 'stm']);
	}

Fatal error: Cannot use object of type Fuel_user_model as array in fuel\modules\fuel\models\Fuel_users_model.php on line 857

https://github.com/daylightstudio/FUEL-CMS/blob/master/fuel/modules/fuel/models/Fuel_users_model.php#L857

Or do I access the model the wrong way?

@daylightstudio
Copy link
Owner

Is $user an empty array or is it Fuel_user_model object do you know? It may be that you need to check if $user exists first. You could also try loading the model and accessing it the "classic" way to see if it makes a difference (which it really shouldn't):

$this->load->module_model(FUEL_FOLDER, 'fuel_users_model');
$user = $this->fuel_users_model->find_one(['user_name' => 'stm']);

@marcus-at-localhost
Copy link
Contributor Author

It's a fuel_user_model object (here is the Kint debug output of the $where param (see linked line above))
image

@daylightstudio
Copy link
Owner

daylightstudio commented Sep 13, 2019

I think I see the issue. Does that error go away when you replace line 857 in Fuel_users_model to?

$this->_parent_model->db()->where(array('super_admin' => 'no'));

@marcus-at-localhost
Copy link
Contributor Author

It's working when I use $this->db()->where(array('super_admin' => 'no')); (_parent_model is not available, because I'm already accessing the parent model?! Not sure)

@daylightstudio
Copy link
Owner

Oh right... for some reason, I thought it was in the record model. This should work as well using db instead of the public method db():

$this->db->where(array('super_admin' => 'no'));

daylightstudio pushed a commit that referenced this issue Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants