Friday, December 7, 2012

Re: Model-query not working with virtualFields

oh.. and if (isset($radius)) {} is pretty bad with false as a default value

either use NULL as default or/AND use just if here:

    if ($radius) {}



Am Freitag, 7. Dezember 2012 16:02:11 UTC+1 schrieb euromark:
this is not google code ;) the method I showed you merely has a "working" distance query to use as virtual field
try to compare that to yours

you should be able to get results if you comment out the conditions!
because then its just a normal query + a mathematical virtual field
if you still get nothing you have some other issue there

yes, you can easily see your query at the bottom of your view (sql debug output when debug mode > 0)
what query does it print?



Am Freitag, 7. Dezember 2012 15:47:05 UTC+1 schrieb Mathias R:
Hi,

sry, but i dont want to use google code. I need to build my own opengeodb-plugin for this app.
All vars are filled and cake displays no errors and no log-messages.
debug($this->Zipcode->listZipcodesNearBy("19370")); has no output.
Cake dumps only first query ($this->findByZipcode) but not second.
I dont know how to solve this.
Is there a way to get the statement how cake build it? Maybe this way i can find any errors.

Am Freitag, 7. Dezember 2012 15:27:16 UTC+1 schrieb euromark:
no errors? just an empty resultset?
what is the query you result in?

Until very recently I got a bug in my distance query, as well. Maybe thats what happens here?
might be just some () missing or $lng instead of $lng somewhere

To confirm that you could try using my (now correctly working) behavior to compare it:

$this->setDistanceAsVirtualField($lat, $lng);

and see if it returns sth now.



Am Freitag, 7. Dezember 2012 15:21:31 UTC+1 schrieb Mathias R:
Hi,

i have a Modelaction where i want to list all zipcodes within a radius nearby another zipcode

    public function listZipcodesNearBy($zipcode = '', $radius = false, $km = 1.609344) {
        if ($data = $this->findByZipcode($zipcode)) {
            $lat = $data['Zipcode']['cityLat'];
            $lng = $data['Zipcode']['cityLng'];
           
            $this->virtualFields['distance'] = '
                ACOS (
                    SIN('.$lat.' * PI() / 180) *
                    SIN(cityLat * PI() / 180) +
                    COS('.$lat.' * PI() / 180) *
                    COS(cityLat * PI() / 180) *
                    COS(('.$lng.' - cityLng) * PI() / 180)
                ) * 180 / PI() * 60 * 1.1515 * '.$km;
           
            $conditions = array();
            if (isset($radius)) {
                $conditions = array("distance <=", (int)$radius);
            }
            return $this->find('list', compact('conditions'));

        }
        return false;
    }

When i don't use virtualfields and comment out $conditions with distance <= $radius i get a list of zipcodes. But with virtualfields there's no output. no errors too..

Do you see the error? Is there a way to print sql statements build in models without action?

Please help.

Greetings from Germany
M.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: