0

Recently, a piece of code stopped working. I haven't made any changes to it so I don't know why.

Here's the code:

$invites = $this->vault_em->getRepository('AppBundle:Invite\LocalInvite')->findBy([
    'active' => true,
]);

Now, it's returning an empty array, even though there are LocalInvite records with active = 1.

Here are the doctrine mappings:

/**
 * @ORM\Entity
 * @ORM\Table(name="invite")
 */
class LocalInvite extends Invite {

    //...

}

/** @ORM\MappedSuperclass */
abstract class Invite implements \JsonSerializable {

    /** @ORM\Column(type="boolean", options={"default": true}) */
    protected $active;

    //...

}

To debug, I copied the underlying MySQL query that Doctrine is executing from the debug logs:

SELECT t0.id AS id_1, t0.email AS email_2, t0.active AS active_3, t0.location AS location_4, t0.cohort_leadership AS cohort_leadership_5, t0.timezone AS timezone_6, t0.date_record_created AS date_record_created_7, t0.date_record_deleted AS date_record_deleted_8, t0.date_restart AS date_restart_9, t0.date_start_invite AS date_start_invite_10, t0.employee_id AS employee_id_11, t0.first_name AS first_name_12, t0.corporate_client_name AS corporate_client_name_13, t0.client_id AS client_id_14, t0.landing_page_url AS landing_page_url_15, t0.user_id AS user_id_16, t0.recipient_id AS recipient_id_17 FROM invite t0 WHERE t0.active = true;

When I plug that query into a MySQL IDE, it returns results.

Why does the findBy return no results?

amacrobert
  • 2,707
  • 2
  • 28
  • 37
  • 1
    Sometimes doctrine's internal cache's go crazy. Try: php bin/console cache:clear && php bin/console doctrine:cache:clear-metadata. Tell me if it worked to add this as an answer. – sh4 Jan 19 '18 at 10:06
  • @sh4 That did not work, and strangely it's occurring on multiple environments (noticed it in production, reproduced locally). – amacrobert Jan 19 '18 at 16:03
  • try 'active' => 1, instead of true – habibun Jan 21 '18 at 08:58
  • @habibun I tried that too (tried true, false, 1, 0, and null -- no results at all). Using DQL instead of the repository method circumvented the problem for now. – amacrobert Jan 24 '18 at 15:44

1 Answers1

-2

try to change 'AppBundle:Invite\LocalInvite' by LocalInvite::class

walidtlili
  • 840
  • 2
  • 13
  • 36
  • While this might help to a solution, it's not an answer but a question to ask the OP in the comment section. – rkeet May 06 '19 at 06:27