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

Cannot use "find" when Model has constructor #25

Closed
rms2219 opened this issue Aug 23, 2013 · 2 comments
Closed

Cannot use "find" when Model has constructor #25

rms2219 opened this issue Aug 23, 2013 · 2 comments

Comments

@rms2219
Copy link

rms2219 commented Aug 23, 2013

I wanted to create a constructor for my model to give some fields some default values. I created the constructor like this:

protected $fillable = array('_id');

public function __construct($attributes = array(), $exists = false)
    {
        parent::construct($attributes, $exists);

        $this->wigets = array();
        $this->starredDocuments = array();
        $this->last_accessed_date = date('m/d/Y g:i:s A'); // e.g. 08/23/2013 1:23:45 PM
    }

My plan requires me to first check if an entry exists with the given key before creating a new one and saving it. When I call "find" on my model, I get a BadMethodCallException: Call to undefined method Jenssegers\Mongodb\Builder::construct()

@jenssegers
Copy link
Contributor

From where are you calling find, and could you provide the full error message?

@jenssegers
Copy link
Contributor

I think I see your error, you have a syntax error in parent::construct($attributes, $exists);, this should actually be parent::__construct($attributes);.

Also, the attributes you are assigning will not be part of your model's attributes. If you want these values to be in your database as wel, add them to the $attributes array before passing it to the parent's constructor.

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