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

[BUG] Model\Query throws fatal error #1529

Closed
quasipickle opened this issue Nov 6, 2013 · 8 comments
Closed

[BUG] Model\Query throws fatal error #1529

quasipickle opened this issue Nov 6, 2013 · 8 comments

Comments

@quasipickle
Copy link
Contributor

Hi,

When I run this code from a model:

$Query = new \Phalcon\Mvc\Model\Query($phql);

I get this output:

Fatal error: Phalcon\Mvc\Model\Query::_prepareSelect(): Call to method load() on a non object in /var/www/htdocs/app/models/Item.php on line 109

I realize this is because I'm not sending my DI container as the second argument. However, I feel this should trigger an exception.

It would seem the second argument is optional, due to the fact PHP isn't throwing an error saying an argument is missing. However I'm guessing code later in the method NEEDS the DI to be set. This should cause an exception to be thrown.

@ghost ghost mentioned this issue Nov 18, 2013
phalcon pushed a commit that referenced this issue Nov 18, 2013
@ghost
Copy link

ghost commented Dec 11, 2013

Can this one be closed now?

@phalcon phalcon closed this as completed Dec 11, 2013
@zyxep
Copy link

zyxep commented Jan 5, 2014

Hi, i am currently running stable 1.2.4 and getting this error of course.
why is it merged into 1.3.0 and not 1.2.5 too?

would it be safe to upgrade to 1.3.0 ?

@ghost
Copy link

ghost commented Jan 6, 2014

@zyxep Those errors are not critical (ie they do not lead to a crash and only happen when the user is misusing the class) and the code in 1.2.x and 1.3.0 has diverged much -- the patch won't apply cleanly, this is why I did not backport the fix into 1.2.5.

As for upgrade -- I do use 1.3.0 in the production and it works like a charm, but your mileage may vary and I would suggest to test 1.3.0 on the dev server first.

@zyxep
Copy link

zyxep commented Jan 6, 2014

then someone should tell me how to use the code then.
The documentation http://docs.phalconphp.com/en/latest/reference/phql.html#creating-phql-queries does say

<?php

// Instantiate the Query
$query = new Phalcon\Mvc\Model\Query("SELECT * FROM Cars", $di);

// Execute the query returning a result if any
$cars = $query->execute();

i use it this way

<?php
use Phalcon\Mvc\Model,
    Phalcon\Mvc\Model\Query;

class Gallery extends Model
{
    public function get_pictures($options = array())
    {
        $sql  = "SELECT p.id, p.filename ";
        $sql .= "FROM pictures p WHERE ";
        $sql .= "p.status = 'active' ";

         $query = new Query($sql);
        return $query->execute();
    }
}

I doesn't see any different from the documentation to my code.
and if there isn't a updated documentation for version 1.3.0 then i think i should use 1.2.4 because i am really new at phalcon :)

@quasipickle
Copy link
Contributor Author

This is a closed bug report - not the place to ask for help with code. Use the forum for that.

@phalcon
Copy link
Collaborator

phalcon commented Jan 6, 2014

Try this:

<?php

use Phalcon\Mvc\Model,
    Phalcon\Mvc\Model\Query;

class Gallery extends Model
{
    public function get_pictures($options = array())
    {
        $sql  = "SELECT p.id, p.filename ";
        $sql .= "FROM pictures p WHERE ";
        $sql .= "p.status = 'active'";
        $query = new Query($sql, $this->getDI());
        return $query->execute();
    }
}

or:

<?php

use Phalcon\Mvc\Model,
    Phalcon\Mvc\Model\Query;

class Gallery extends Model
{
    public function get_pictures($options = array())
    {
        return Pictures::find(array(
            'columns' => 'id, filename',
            'conditions' => 'status = "active"'
        ))
    }
}

@zyxep
Copy link

zyxep commented Jan 6, 2014

Thanks it helped, i will not disturb you anymore :)

@bhoopal10
Copy link

how to join two table by using common id? sorry my bad English :(

'question_id', 'questionModuleID' => 'questionModuleID', 'questionText' => 'questionText', 'questionOptions' => 'questionOptions', 'questionMarks' => 'questionMarks' ); } public function initialize() { $this->hasMany("questionModuleID","Module","module_id"); } ```

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

3 participants