analogueorm / analogue

Analogue ORM : Data Mapper ORM for Laravel/PHP
MIT License
635 stars 52 forks source link

Fix EmbedsMany #256

Closed cappuc closed 6 years ago

cappuc commented 6 years ago

EmbedsMany attributes must be array but the array needs to be serialized to json before generating sql query

RemiCollin commented 6 years ago

Thanks for pointing this out.

Indeed the embedsMany() is not usable as it is on most SQL system, but the case is that some Database drivers (ie MongoDB) do not need this conversion, so I think we cannot generalize it. Also, my initial idea was to take advantage of new Mysql json for this feature.

But I agree having the possibility to cast/uncast to json would be a great addition for DB layer not supporting json type.

Let's make it optional : instead of calling asArray() , we would call asJson() method on the relationship object, so it's clear in which format the user wants his data stored in the database. What do you think ?

cappuc commented 6 years ago

Yes, adding the asJson() method can resolve the problem and allow the user to choice in which format the data is stored in the database

if I have some free time, I can try to implement the asJson() method

RemiCollin commented 6 years ago

I think, for consistency, this method should be available on both embedsOne and embedsMany relationships. Implementation should be pretty straightforward, still don't hesitate if you have any doubt or question.

RemiCollin commented 6 years ago

Looks good @cappuc