iluvadev / PocketBaseClient

C# client to interact with a particular PocketBase application: an ORM mapped to your PocketBase server. [This project is in active development. The things described below could change]
MIT License
34 stars 8 forks source link

Fix not working relation list #13

Closed mtaku3 closed 1 year ago

mtaku3 commented 1 year ago

Hi, when I was using ORM for my project, I found out that list of relation and enum isn't working. Specifically, CollectionList and EnumList.

There are two reasons that it is not working.

  1. JsonSerializer doesn't serialize readonly property. CollectionList and EnumList are readonly(setter is private, not public) in auto-generated code. JsonSerializer skips these properties. To include, we need to add [JsonInclude] attribute to property explicitly.
  2. FieldBasicList doesn't have implementation of object? IBasicList.Add(object? element) Looks like setter of these properties calls Set => UpdateWith => Add But FieldBasicList class doesn't have implementation of object? IBasicList.Add(object? element). (returning null) I added implementation using FieldBasicList.Add. So that element will be added to the inner list properly. (I added implementation of object? IBasicList.Remove(object? element) as well because I think it is necessary.)

Also, current implementation of

        bool IBasicList.Contains(object? element)
            => false;

in FieldBasicList class maybe wrong?

I don't fully understand the code so maybe some part are wrong. Sorry for that.

iluvadev commented 1 year ago

I changed

bool IBasicList.Contains(object? element)
    => false;

To

bool IBasicList.Contains(object? element)
    => element is T item && Contains(item);

Thanks @mtaku3