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

Initialize on Model __construct #556

Closed
daylightstudio opened this issue Jun 17, 2017 · 5 comments
Closed

Initialize on Model __construct #556

daylightstudio opened this issue Jun 17, 2017 · 5 comments

Comments

@daylightstudio
Copy link
Contributor

I ran into an issue where I wanted to escape a string for a where condition in a model's method but it was throwing an error in the Connection::_escapeString method because $this->connID was returning false. I noticed I had to call the initialize method first for it to work. Is there a reason why this isn't automatically called in the Model's constructor?

@lonnieezell
Copy link
Member

Mainly to keep it similar to the way CI3 works, where the model class can be loaded without the relatively slow process of connecting to the db. Some people have a tendency to load up a chunk of model's before doing checks, I guess, and it helps keep the performance up. There might have been other reasons, but I don't recall at the moment. It's been a while. :)

In your specific case - you shouldn't need to escape the data before passing it into a Query Builder where clause - that's taken care of for you automatically by the database engine.

@daylightstudio
Copy link
Contributor Author

In my case, I had a where condition that needed to be written as a string because of some parenthesis for order of operation and needed to escape a string value. It was not as an array or the 2 parameter key, value. Probably should have mentioned that in the initial post.

@daylightstudio
Copy link
Contributor Author

I'm curious why this was closed? I could see this still potentially being an issue for folks that are using where conditions written as strings instead of arrays or the the 2 parameters key, value.

@lonnieezell
Copy link
Member

Because it was fixed in the commit referenced above. :)

@daylightstudio
Copy link
Contributor Author

My bad... I'll check that next time. Thanks man... I really do appreciate all your efforts with this project.

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