We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

InvalidArgumentException: Parameter 'name' must be a string

After update from phalcon 2.8 to 3.0.3 and php7.0 i have error InvalidArgumentException: Parameter 'name' must be a string It happend's when try to get belongsTo relation

use Phalcon\Mvc\Model\Resultset\Simple as Resultset;

class Country extends GeonameAbstractModel
{

    /**
     *
     * @var string
     */
    protected $iso_alpha2;

     /**
     *
     * @var integer
     */
    protected $geonameid;
    ......
    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        $this->setSchema("public");
        $this->belongsTo('geonameid', 'Geoname', 'geonameid', array('alias' => 'Geoname'));
    }

    /**
     * Virtual method for IDE.
     *
     * @param mixed $parameters
     * @return \Geoname
     */
    public function getGeoname($parameters = null)
    {
        return $this->getRelated('Geoname', $parameters);
    }
    ....
}

class Geoname extends \Phalcon\Mvc\Model
{

    public static $lang='en';

    /**
     *
     * @var integer
     */
    protected $geonameid;
    ......
     /**
     * Initialize method for model.
     */
    public function initialize()
    {
        $this->setSchema("public");
        $this->hasMany('geonameid', 'Admin1Codes', 'geonameid', array('alias' => 'Admin1Codes'));
        $this->hasMany('geonameid', 'Admin2Codes', 'geonameid', array('alias' => 'Admin2Codes'));
        $this->hasMany('geonameid', 'Translate', 'geonameid', array('alias' => 'Translations'));
        $this->hasMany('geonameid', 'Continent', 'geonameid', array('alias' => 'ContinentCodes'));
        $this->hasMany('geonameid', 'Country', 'geonameid', array('alias' => 'Countryinfo'));
        $this->hasMany('geonameid', 'Hierarchy', 'parent_id', array('alias' => 'ParentsHierarchy'));
        $this->hasMany('geonameid', 'Hierarchy', 'child_id', array('alias' => 'ChildsHierarchy'));
    }
  ....
}

$country->getGeoname(); //InvalidArgumentException: Parameter 'name' must be a string

All tables exists, this code runs on php 5.6 phalcon 2.8 without problems.



17.5k
edited Feb '17

Backtrace

#0  Phalcon\Db\Column->__construct(2177478, Array([bindType] => 2, [type] => 2, [first] => 1))
#1  Phalcon\Db\Adapter\Pdo\Postgresql->describeColumns(geoname, public)
#2  Phalcon\Mvc\Model\MetaData\Strategy\Introspection->getMetaData(Object(Geoname: ), Object(Phalcon\Di\FactoryDefault))
#3  Phalcon\Mvc\Model\MetaData->_initialize(Object(Geoname: ), geoname-publicgeoname, geoname, public)
#4  Phalcon\Mvc\Model\MetaData->readMetaData(Object(Geoname: ))
#5  Phalcon\Mvc\Model\MetaData->hasAttribute(Object(Geoname: ), geonameid)
#6  Phalcon\Mvc\Model\Query->_getQualified(Array([type] => 355, [name] => geonameid))
#7  Phalcon\Mvc\Model\Query->_getExpression(Array([type] => 355, [name] => geonameid), true)
#8  Phalcon\Mvc\Model\Query->_getExpression(Array([type] => 61, [left] => Array([type] => 355, [name] => geonameid), [right] => Array([type] => 274, [value] => APR0)))
#9  Phalcon\Mvc\Model\Query->_prepareSelect()
#10 Phalcon\Mvc\Model\Query->parse()
#11 Phalcon\Mvc\Model\Query->execute()
#12 Phalcon\Mvc\Model::findFirst(Array([0] => [geonameid] = :APR0:, [bind] => Array([APR0] => 2077456), [di] => Object(Phalcon\Di\FactoryDefault)))
/var/www/weather.town/app/models/Geoname.php (675)

#13 Geoname::findFirst(Array([0] => [geonameid] = :APR0:, [bind] => Array([APR0] => 2077456), [di] => Object(Phalcon\Di\FactoryDefault)))
#14 Phalcon\Mvc\Model\Manager->getRelationRecords(Object(Phalcon\Mvc\Model\Relation), null, Object(Country: [db] => (empty string), [search_tsv] => 'ahitereiria':2 'ao':78 'aositelelia':1 'aostralia':7 'astireliya':82 'astr':84 'astrail':4 'astralia':8,61 'astralya':83 'astreliya':86 'astráil':6 'austraalia':9 'austraila':10 'australi':11,19 'australia':12,13,15,17,51,90,175 'australien':20 'australija':21 'australio':22 'australië':23 'australya':24 'austràlia':25 'austráli':27 'austrália':26 'austrālija':28 'ausztralia':29 'ausztrália':30 'autereraria':31 'avstrali':32 'avstralia':33 'avstralij':35 'avstralija':34 'avstraliya':38 'avstrualii':39 'avustralya':40 'awistralya':41 'awstaraaliya':42 'awstralia':43 'awstralja':44 'awstralska':45 'awstralya':46 'awusitureliya':47 'aŭstralio':48 'commonwealth':49,173 'da':79 'e':97 'hoju':87 'i-australia':88 'i-ostreliya':52 'kij':36 'li':58,80 'lī':104 'nutom':18 'o':56 'o-tai-li-a':55 'orileed':60 'orílẹ́èd':62 'oseuteuleillia':91 'ositali':64 'ositaraliya':65 'ositirali':66 'ositáli':67 'ostaraalii':68 'ostareliya':69 'ostaruliya':167 'ostrali':70 'ostralii':71 'ostralïi':73 'ostrelia':75 'ostreliya':54,92 'osutoraria':93 'otereiriya':76 'prath':94 'sojuz':37 'sotralii':72 'sotralïi':74 'sralygu':96 'tai':57 'tāi':103 'uc':14,77 'xxsterleiy':95,98 'ya':81 'yavstyralyyە':99 'ástralía':100 'ástràlìá':63 'ò':102 'ò-tāi-lī-a':101 'úc':16,106 'ɔstrelia':107 'ʻaositelēlia':108 'ʾwstrlyʾ':109 'αυστραλία':110 'австрали':111 'австралия':112 'австралија':113 'австралійський':114 'австралія':116 'аустралија':117 'аўстралія':118 'союз':115 'ավստրալիա':119 'אויסטראליע':120 'אוסטרליה':121 'אױסטראַליע':122 'آسٹریلیا':123 'آسټراليا':124 'أستراليا':125 'ئاۋستىرالىيە':126 'ئۆسترالیا':127 'استراليا':128 'استرالیا':129 'ܐܘܣܛܪܠܝܐ':130 'އޮސްޓަރުލިޔާ':131 'अष्ट्रेलिया':132 'ऑस्ट्रेलिया':133 'অস্ট্রেলিয়া':134 'অস্ট্রেলিয়া':135 'ઑસ્ટ્રેલિયા':136 'ଅଷ୍ଟ୍ରେଲିଆ':137 'ஆஸ்திரேலியா':138 'ఆస్ట్రేలియా':139 'ಆಸ್ಟ್ರೇಲಿಯ':140 'ഓസ്ട്രേലിയ':141 'ඕස්ට්‍රේලියාව':142 'ประเทศออสเตรเลีย':143 'ออสเตรเลีย':144 'ອົອດສະຕາລີ':145 'ཊེཡེ':152 'ཐ':148 'ཐེ':160 'ཡ':150,154,157,162 'ལ':149 'ལི':153,156,161 'ས':147 'སེ':159 'ཨ':146 'ཨས':151 'ཨསྟྲེ':155 'ཨོ':158 'ဩစတြေးလျ':163 'ავსტრალია':164 'አውስትሬሊያ':165 'អូស្ត្រាលី':166 'オーストラリア':168 '澳大利亚':169 '澳大利亞':170 '오스트레일리아':171 '호주':172), null)
#15 Phalcon\Mvc\Model->getRelated(Geoname, null)

Idk, maybe try to clear metadata if you are using apc/memcache or files?



17.5k
Accepted
answer

the problem was on my class that overide phalcon Postgress connection for cache all queries, what a problem i don't understend but now but it's not a phalcon side