0

First things first. I am totally new on Symfony, and I am trying to solve an issue but I don't know how. So, if my questions seem to weird to you, then please help me by explaining where I am wrong and thank you in advance.

So, in my DB I have the following tables:

payments, with columns: id, merchant_sevice_id, customer_id, status, type, created_at, amount_amount, amount_currency. payment_method_payment_method_type, payment_method_payment_method_id, vat and failed_reason.

and

merchant_services with columns: id, payment_institution_id, account_id, name, capacity, capabilities, created_at, mid, status, and blocked_bins_id.

The two tables are connected with a manyToOne relationship. So, many payments could belong to one Merchant

Now, the problem is when I try to get one Payment and check the relationship with Merchants. The fields of the Merchant are all nulled, while in DB I have values.

So a given record in payments table looks like that:

| id                                   | merchant_service_id                  | customer_id                          | status | type | created_at           | amount_amount | amount_currency | payment_method_payment_method_type | payment_method_payment_method_id     | vat | failed_reason |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 0fede82a-b898-4287-83e3-8f7d28d576db | 548d36d9-f1e6-4854-b513-1559b2499b45 | 237369c4-feed-4e24-964a-638938c7940c | failed | SALE |  2018-06-15 07:36:28 | 100           | GBP             | card                               | f35f78c4-2da7-432a-ace5-c0829db448af | 5   |               |

And the related record in merchants is like that:

| id                                   | payment_institution_id               | account_id                           | name | capacity | capabilities | created_at          | mid | status | blocked_bins_id                      |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 548d36d9-f1e6-4854-b513-1559b2499b45 | c7a02b53-6c8b-4aa9-b1af-1c5b4978d844 | 4d239c0f-1fa0-4d70-88b4-95b6f05e7bf5 | Test | 0        | ["AUTH"]     | 2018-06-06 06:36:15 | 53  | active | e3d6a222-68cd-468c-a78a-b0da8ff0caf9 |

Then, the output of my query in the DB seems like that:

enter image description here

As you could see, the values of the merchantService are all null (except the ID).

So the question is, what it could make this problem? Could be a serializer? Is that a kind of Symfony issue? Actually I am looking for a hint on where to look for solution of that issue.

Again sorry if my question is too weired, but I am really blocked and I don't know how to continue.

KodeFor.Me
  • 13,069
  • 27
  • 98
  • 166
  • 4
    Doctrine relationships are lazy-loaded (unless you specify otherwise). I suspect what you're looking at there is a proxy object - you should still be able to use any getter methods to actually fetch the properties, at which point it'll go back to the database and fetch the full object. – iainn Sep 05 '18 at 10:45
  • 4
    Possible duplicate of [doctrine2 association is not initialized](https://stackoverflow.com/questions/13431614/doctrine2-association-is-not-initialized) – iainn Sep 05 '18 at 10:46
  • 1
    My psychic powers suggest that Payment::setMerchant($merchant) is never being called. Doctrine allows you to map relationships but it's up to you to actually set them. – Cerad Sep 05 '18 at 12:29

1 Answers1

2

As iainn indicated in his comment Doctrine relationships are by default lazy-loaded (you can change that by using fetch="EAGER" in the ManyToOne annotation). Indeed, you can easily observe that in your screenshot, as the merchantService object has property __isInitialized__ set to false. That means it is a proxy object of MerchantService class.

enter image description here

iiirxs
  • 4,493
  • 2
  • 20
  • 35