简体   繁体   English

教义2数组集合计数()php

[英]doctrine2 arraycollection count() php

i have the following code:我有以下代码:

        $countries = $em->getRepository("country")->findAll();
        $array = array();
        $count = 0;
        foreach($countries as $country){
            if(is_object($country)){
                if($country->getCompaniesCount() > 0)
                $array[$count] = $country;
                $count++;
            }
        }

And the "getCompaniesCount" function which is called looks like this:调用的“getCompaniesCount”函数如下所示:

    public function getCompaniesCount(){
        return $this->_comapanies->count();
    }

but it produces an error which i cannot understand.但它会产生一个我无法理解的错误。

There ARE countries in "country", and there ARE "companies" which are related to countries. “country”中有国家,有与国家相关的“公司”。 so country and company is a ManyToMany-Relationship.所以国家和公司是多对多关系。 And the attribute "_companies" in "country" is initialised as an ArrayCollection to hold the companies.并且“country”中的属性“_companies”被初始化为 ArrayCollection 来保存公司。

But everytime i run this code i get the following error:但是每次我运行此代码时,都会出现以下错误:

Catchable fatal error: 
Argument 1 passed to   Doctrine\ORM\Mapping\DefaultQuoteStrategy::getJoinTableName() must be an array, null given, 
called in /usr/share/pear/Doctrine/ORM/Persisters/BasicEntityPersister.php on line 965 
and defined in /usr/share/pear/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php on line 86

does anyone have an idea why?有谁知道为什么?

thanks谢谢

ohhh noooo.哦不。 i feel so dumb.我觉得很愚蠢。 just a wrong foreign-key-name -.-.只是一个错误的外键名-.-。

solved.解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM