Reputation: 15
// This is my entity class object
use Doctrine\ORM\Mapping as ORM;
class PayOrder {
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string",unique=true)
*/
private $pay_no;
};
// I use it in my function, this is the Repository
use Doctrine\ORM\EntityManager;
use Exception;
use Psr\Container\ContainerInterface;
use Doctrine\ORM\Mapping;
class PayOrderRepository extends \Doctrine\ORM\EntityRepository {
public function get( PayOrder $payOrder ) {
$pay_no=$payOrder->getPayNo();
// It will occurs a exception, how to fix it, any one can help me?
return $this->findBypayno($pay_no);
}
};
Besides that, I can't find the document to fix the problem.
I want to use the field name pay_no
, and I want to use the repository
findbyxxx, but I do not how to use it correctly.
Upvotes: 1
Views: 1402
Reputation: 766
Or just use
$this->findBy(['pay_no' => $payOrder->getPayNo());
The findByX
method are just intercepted method calls - see line up 177 to 179 that are transformed to findBy
calls.
Upvotes: 0
Reputation: 1071
Change your property name to $payNo
.
Probably in your entity look like that;
//...
/**
* @ORM\Column(type="string", length=255)
*/
$pay_no
//....
Change it like that;
//...
/**
* @ORM\Column(name="pay_no", type="string", length=255)
*/
$payNo
//....
After that,
$pay_no
app/console doctrine:generate:entities
bin/console make:entity --regenerate
Goodluck. If you have any question or blocker please write me.
Upvotes: 2