> For the complete documentation index, see [llms.txt](https://entity-factory.gitbook.io/entity-factory/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://entity-factory.gitbook.io/entity-factory/builder.md).

# Using the Builder

The builder is accessed via an entity factory instance by calling the `for()` method.

```javascript
factory
    .for('user')
    .state('active')
    .with({
        email: 'test@test.com',
    })
    .create();
```

## Builder Methods

### state(...string)

Used to apply defined state transforms to a factory. The states are applied the order they are provided to the function.

```javascript
factory.for(User).state('active', 'with-posts');
```

### with(partial)

Used for overriding properties on a created entity. This is particularly useful when testing for a specific value.

```javascript
factory.for(User).with({
    name: 'john',
});
```

### make(\[int, \[partial]])

Resolves the partials generated by the factory methods and converts them into plain objects or class instances. Unlike `create()` the entity will not be persisted

```javascript
// return a single User
factory.for(User).make();
factory.for(User).make({ active: true });
factory.for(User).make(1);
factory.for(User).make(1, { active: true });

// return an array of User
factory.for(User).make(2);
factory.for(User).make(2, { active: true });
```

### create(\[int, \[partial]])

Resolves and persists the partials generated by the factory methods and converts them into plain objects and class instances. Depending on the adapter this can mean that they simple have an id generated for them or they are saved to teh database.

```javascript
// return a single User
factory.for(User).create();
factory.for(User).create({ active: true });
factory.for(User).create(1);
factory.for(User).create(1, { active: true });

// return an array of User
factory.for(User).create(2);
factory.for(User).create(2, { active: true });
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://entity-factory.gitbook.io/entity-factory/builder.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
