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

Updating docs for DS.FixtureAdapter #49

Merged
merged 1 commit into from
Jan 12, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -853,9 +853,7 @@ test("Creates new project", function() {
- FactoryGuy.make ... creates model in the store and returns json

Technically when you call FactoryGuy.make with a store using the DS.FixtureAdapter,
the fixture is actually added to the models FIXTURE array. It just seems to be added
to the store because when you call store.find to get that record, the adapter looks
in that FIXTURE array to find it and then puts it in the store.
the fixture is added to the model's FIXTURE array and also pushed into the store. Normally the store is populated by the DS.FixtureAdapter when you call store.find.


```javascript
Expand All @@ -865,10 +863,11 @@ FactoryGuy.make('user', {name: 'bob'}); // user.FIXTURES = [{id: 2, name: 'bob'
FactoryGuy.make('admin'); // user.FIXTURES = [{id: 3, name: 'Admin', style: 'super'}]
FactoryGuy.make('admin', {name: 'Fred'}); // user.FIXTURES = [{id: 4, name: 'Fred', style: 'super'}]

// This works because we push the models into the store when called FactoryGuy.make
var userJson = FactoryGuy.make('user'); // user.FIXTURES = [{id: 1, name: 'User1', style: 'normal'}]
store.all('user') // returns the user equal to userJson

// Use store.find to get the model instance ( Remember this is the Fixture adapter, if
// you use the ActiveModelAdapter or RESTAdapter the record is returned so you don't
// have to then go and find it )
// Use store.find to get the model instance
var userJson = FactoryGuy.make('user');
store.find('user', userJson.id).then(function(user) {
user.toJSON({includeId: true}) ( pretty much equals ) userJson;
Expand All @@ -881,8 +880,15 @@ var userJson = FactoryGuy.make('user', {projects: [projectJson.id]});
var userJson = FactoryGuy.make('user');
var projectJson = FactoryGuy.make('project', {user: userJson.id});

// will give you the same result, but with fixture adapter all associations
// are treated as async ( by factory_guy_has_many.js fix ), so it's
// Associations are pushed on as well
store.find('user', 1).then(function (user) {
var projects = user.get('projects');
projects.get('length'); //1
projects.get('firstObject').toJSON({includeId: true}); //equal to projectJSON
});

// If you are using factory_guy_has_many.js fix, will give you the same result,
// but all associations are treated as async, so it's
// a bit clunky to get this associated data. When using DS.FixtureAdapter
// in view specs though, this clunk is dealt with for you. But remember,
// you DON'T have to use the Fixture adapter.
Expand Down