Creating a models directory in pods?

I’m using pods, and I’m wondering if there’s a way to have a app/pods/models directory where all my models go much like there’s a app/pods/components directory? I thought about just using the non-pod layout (ie, apps/models); however, each of my models has a serializer and an adapter, and I want those grouped together.

In other words, is it possible to have, for example:

app/
  pods/
    models/
      author/
        model.js
        adapter.js
        serializer.js
      book/
        model.js
        adapter.js
        serializer.js
1 Like

With current pods, no. You can pass the flag --pod while generating your models and have them all nested outside of the pods folder though. But that then splits your adapters, serializers and models.

What you want is what we all want, which is described here: https://github.com/emberjs/rfcs/pull/143

I actually tried a bit of a hack that seems to work. I used:

ember generate model|adapter|serializer models/book

In my adapter, I modified buildUrl to remove the “models” part from modelName='models/book'. And in my serializer, I modify the payload to return "models/books" as the base property. And to retrieve a record, it’d be: this.store.findRecord('models/book', 123);

It’s ugly, and I’m actually thinking it might not be worth it as I add more models. But it does seem to work.

But I do look forward to the changes in the PR you referenced.

It’s certainly not perfect at the moment and I’ve found I use the pod layout for route/controller/template but I stick to non-pod for model/adapter/serializer.

The proposal referenced above is definitely an improvement in some areas but it is not terribly easy to grok and my fear is it will be (yet) another thing that puts people off using Ember and will also mean some hefty work for everyone who has written an add-on.

I think a major part of the problem is you can’t satisfy everyone because there are some strong personal opinions on folder layout (some of which come from not wanting to change how we work rather than believing how we work is actually the best approach).

I have found personally that one of the unexpected downsides of a modular approach is how many files you end up with. My current main Ember app isn’t that complex but I have almost 1,100 files in my app folder and at times it can be quite overwhelming. It’s been a solo project so far but I am not looking forward to trying to run through it with my team because even explaining the file/folder structure could take a long time and that’s before I start explaining what they do!

1 Like

Yes this is definitely an issue. File management is a real task. In non-pod form it’s the lack of structure leading to a very long, flat, list of components, and with pods everything having the same file name makes things like file search and the chrome inspector pretty nasty.

I’m currently using pods just for components, and nesting sub components when a component is only used in the context of a parent.

It would be nice model/adapter/serializer could be wrapped into a single file maybe in a similar fashion to how actions are…


{
        model: function(){
        // model here
        },
        adapter: function(){
        // adapter here
        },
        serializer: function(){
       // serializer here 
        }
}