adopted-ember-addons/ember-data-factory-guy

Aliasing property to associated model

cinkonaap opened this issue · 2 comments

I wonder is it possible to make a property of a factory aliased to associated model property.

In my case let's imagine I do have factory for a model Bot

FactoryGuy.define('bot', {
  default: {
    name: null,
  },
  traits: {
    jimmy: {
      name: 'Jimmy Guy',
   },
 }
}

And a factory for model Game

FactoryGuy.define('game', {
  traits: {
    game_on: {
      bot: FactoruGuy.belongsTo('bot', 'jimmy'),
      botName: // how to alias?
    },
  },
});

Answering your question "Why can't I just do game.get('bot.name') up front, it's because my case is not as trivial as one mentioned above, and I've wondered whether I could make a botName property aliased to bot.name somehow, to make my factories more clean. I've already tried to use inline functions and computed.alias but couldn't make it work.

Of course anything is possible, but that sounds like massive hackery to me, and as much as hackery can be a good thing, this seems to smack of a bit too much.
What I would do is use scene builders, where you build data in a class and uses factories but also has methods to put together data as you need it, so it is an abstraction above the factory level.
That is what I do for cases like these.

@danielspaniel Sounds reasonable, thanks for your input.