Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue: sub collections on different files #2

Open
diegogarciar opened this issue Feb 2, 2024 · 0 comments
Open

issue: sub collections on different files #2

diegogarciar opened this issue Feb 2, 2024 · 0 comments

Comments

@diegogarciar
Copy link

diegogarciar commented Feb 2, 2024

Expected Behavior

I would like to propose to add back the ability to have different collections on different files. The reason this was added can be related to this reported issue firebase/flutterfire#11236.

As summary the sub collection needs to access the _$$ObjectImplFieldMap which is created on the .g.dart file and not explicitly available on other clases.

I believe this is not a good enough excuse as json_serializable has exactly the same problem, models that depend on other models cannot access the private variables or methods, so we are required to expose them not only for our usage, but also so that other constructors can use it.

In this example we can see how modelB depends on modelA, where on modelA we didn't exposed the _$ModelAFromJson method via the factory constructor ModelA.fromJson. However the _$ModelBFromJson is assuming that ModelA.fromJson is defined, which causes a compile error.

image

My proposal is that we do the same that json_serializable does, we simply define in the documentation that the _$$ObjectImplFieldMap must be exposed, it works for me on the build 62 but I want to keep my packages updated.

if we add to the documentation that we must expose the field map as such, we can bring back sub collections on separate files.

static Map<String, String> get fieldMap => _$$ObjectImplFieldMap

for my current workaround I also need to do a

// ignore: non_constant_identifier_names
Map<String, String> _$$_ObjectFieldMap = Object.fieldMap;

but I guess we can just update the generator so that it looks for Object.fieldMap instead of the _$$_ObjectFieldMap

Actual Behavior

When using json_serializable, the @Collection annotation and the class that
represents the content of the collection must be in the same file.

Steps to Reproduce the Problem

  1. Build a model ModelA for subcollection 'parent' on file model_a.dart
  2. Build a subccollection ModelB, which is a sub collection of 'parent' on file model_b.dart
  3. You'll get an error that the sub collection can't be on a separate file

Specifications

  • Version: 1.0.0-dev.82
  • Platform: any
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant