in app.initializers.add callback app.store.all('mymodel') is always return [] ( but it's not and will be handled with app after initializers callback ). I'm also can't make any API requests in this callback because of app.request is not initialized yet. And question is how to get my models in frontend extension initializator callback?

    bradraj app.store.all is sort of a fancy alias for app.request to /api/{model}s + app.store.pushObject, so it will obviously not be available before app.request.

    If you need this data on every page load, before the first page has been rendered, what you probably want instead is pre-loaded data. You could add a new relationship on the forum virtual model, which lets you access your models. That's how the original version of FoF Terms worked for example, though it has now been changed to only load terms when the terms modal appears. I can't think if any current example.

    Alternatively if you need your data for a specific page, you could extend the page oninit hook. If you have multiple pages, you can extend the parent Page.oninit then check which page has been loaded and have a flag that tells you whether your data was already loaded in this browser tab. Or hook into the page resolver for the same effect.

      clarkwinkelmann

      You could add a new relationship on the forum virtual model, which lets you access your models.

      Yes, I'm doing exactly this but there no any models loaded during execution of app.initializers.add callback. No groups and any other models.

      For example I'm trying to get all groups on the forum ( that already have relationships with forum virtual model )

      app.initializers.add('myext', () => {
      	app.store.all('groups') // returns []
      });

      clarkwinkelmann and I'm need to access to my models exactly in ext-initializatior callback because of some options of initialization is depended on models data

      Oops, disregard my post, I mixed up the name of the methods, store.all has nothing to do with the REST API, it would indeed work to retrieve pre-loaded data through relations.

      To get access to data this early, you would probably have to add your attributes directly to app.data without using the models and store at all, because those concepts are indeed not available this early in the app lifecycle (because extensions can still register and modify model definitions). I don't remember the name of the extender that lets you modify app.data server-side though. That's where Flarum stores the language for instance, as it needs to be available early.

        clarkwinkelmann okay, thanks. I thought there was another way then directly modifying of app.data and access them after.