question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Array of Objects using Factory.get

See original GitHub issue

I’ve the impression that this is yet another use case that it is not supported at the moment. #15 and #14 seems related to this one, but not quite.

Running this define I get a RangeError: Maximum call stack size exceeded Error …

Factory.define('fakeTeam',Volunteers.Collections.Teams,
  {
    'name': () -> faker.company.companyName()
    'visibility': 'public',
    'leads': () -> [ {'userId': Factory.get('fakeUser'), 'role': 'lead'} ]
    'tags': () -> [faker.lorem.words()],
    'parents':[],
  })

I can’t find a better title to describe this problem …

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
dburlescommented, Apr 7, 2017

Looks like what you’re trying to do isn’t supported yet 😔, as you can see by this test: https://github.com/versolearning/meteor-factory/blob/master/factory_tests.js#L337-L346

In the meantime you can just do this:

import { Random } from 'meteor/random';

Factory.define('fakeTeam', Teams, {
  'name': function() { return faker.company.companyName(); },
  'leads': function() { return [{'userId': Random.id(), 'role': 'lead'}]; }
});

The only downside to this would be if you wished to use Factory.tree, though I wouldn’t imagine your intention would be to store the complete user document within the array.

1reaction
abatecommented, Apr 7, 2017

Another solution might be something like :

> getRandomUser = () ->
>   _.sample(Factory.get('fakeUser').collection.find().fetch())

and

'leads': function() { return [{'userId': getRandomUser()._id, 'role': 'lead'}]; }

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pushing Objects From Function Factories into Arrays
I want to have a function that takes the difference between the total zombie health versus total human attack. It works with one...
Read more >
How to Create Objects Using Factory Functions in JavaScript
This article will cover building an object using factory functions, followed by an article covering constructor functions and using the new ...
Read more >
JavaScript Factory Functions
A factory function is a function that returns a new object. Use Object.create() to create an object using an existing object as a...
Read more >
Factory: Encapsulating Object Creation
The actual creation of shapes is performed by calling ShapeFactory.createShape( ), which is a static method that uses the dictionary in ShapeFactory to...
Read more >
Factory Method - Refactoring.Guru
The Factory Method pattern suggests that you replace direct object construction calls (using the new operator) with calls to a special factory method....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found