# Add custom methods to your models (/docs/orm/prisma-client/client-extensions/model)

Location: ORM > Prisma Client > Client Extensions > Add custom methods to your models

You can use the `model` [Prisma Client extensions](/orm/prisma-client/client-extensions) component type to add custom methods to your models.

Possible uses for the `model` component include the following:

* New operations to operate alongside existing Prisma Client operations, such as `findMany`
* Encapsulated business logic
* Repetitive operations
* Model-specific utilities

Add a custom method [#add-a-custom-method]

Use the `$extends` [client-level method](/orm/reference/prisma-client-reference#client-methods) to create an *extended client*. An extended client is a variant of the standard Prisma Client that is wrapped by one or more extensions. Use the `model` extension component to add methods to models in your schema.

Add a custom method to a specific model [#add-a-custom-method-to-a-specific-model]

To extend a specific model in your schema, use the following structure. This example adds a method to the `user` model.

```ts
const prisma = new PrismaClient().$extends({
  name?: '<name>',  // (optional) names the extension for error logs
  model?: {
    user: { ... }   // in this case, we extend the `user` model
  },
});
```

Example [#example]

The following example adds a method called `signUp` to the `user` model. This method creates a new user with the specified email address:

```ts
const prisma = new PrismaClient().$extends({
  model: {
    user: {
      async signUp(email: string) {
        await prisma.user.create({ data: { email } });
      },
    },
  },
});
```

You would call `signUp` in your application as follows:

```ts
const user = await prisma.user.signUp("john@prisma.io");
```

Add a custom method to all models in your schema [#add-a-custom-method-to-all-models-in-your-schema]

To extend *all* models in your schema, use the following structure:

```ts
const prisma = new PrismaClient().$extends({
  name?: '<name>', // `name` is an optional field that you can use to name the extension for error logs
  model?: {
    $allModels: { ... }
  },
})
```

Example [#example-1]

The following example adds an `exists` method to all models.

```ts
const prisma = new PrismaClient().$extends({
  model: {
    $allModels: {
      async exists<T>(this: T, where: Prisma.Args<T, "findFirst">["where"]): Promise<boolean> {
        // Get the current model at runtime
        const context = Prisma.getExtensionContext(this);

        const result = await (context as any).findFirst({ where });
        return result !== null;
      },
    },
  },
});
```

You would call `exists` in your application as follows:

```ts
// `exists` method available on all models
await prisma.user.exists({ name: "Alice" });
await prisma.post.exists({
  OR: [{ title: { contains: "Prisma" } }, { content: { contains: "Prisma" } }],
});
```

Call a custom method from another custom method [#call-a-custom-method-from-another-custom-method]

You can call a custom method from another custom method, if the two methods are declared on the same model. For example, you can call a custom method on the `user` model from another custom method on the `user` model. It does not matter if the two methods are declared in the same extension or in different extensions.

To do so, use `Prisma.getExtensionContext(this).methodName`. Note that you cannot use `prisma.user.methodName`. This is because `prisma` is not extended yet, and therefore does not contain the new method.

For example:

```ts
const prisma = new PrismaClient().$extends({
  model: {
    user: {
      firstMethod() {
        ...
      },
      secondMethod() {
          Prisma.getExtensionContext(this).firstMethod()
      }
    }
  }
})
```

Get the current model name at runtime [#get-the-current-model-name-at-runtime]

You can get the name of the current model at runtime with `Prisma.getExtensionContext(this).$name`. You might use this to write out the model name to a log, to send the name to another service, or to branch your code based on the model.

For example:

```ts
// `context` refers to the current model
const context = Prisma.getExtensionContext(this);

// `context.$name` returns the name of the current model
console.log(context.$name);

// Usage
await (context as any).findFirst({ args });
```

Refer to [Add a custom method to all models in your schema](#example-1) for a concrete example for retrieving the current model name at runtime.

Advanced type safety: type utilities for defining generic extensions [#advanced-type-safety-type-utilities-for-defining-generic-extensions]

You can improve the type-safety of `model` components in your shared extensions with [type utilities](/orm/prisma-client/client-extensions/type-utilities).

## Related pages

- [`Add custom fields and methods to query results`](https://www.prisma.io/docs/orm/prisma-client/client-extensions/result): Extend the functionality of Prisma Client, result component
- [`Add methods to Prisma Client`](https://www.prisma.io/docs/orm/prisma-client/client-extensions/client): Extend the functionality of Prisma Client, client component
- [`Create custom Prisma Client queries`](https://www.prisma.io/docs/orm/prisma-client/client-extensions/query): Extend the functionality of Prisma Client, query component
- [`Shared packages & examples`](https://www.prisma.io/docs/orm/prisma-client/client-extensions/extension-examples): Explore the Prisma Client extensions that have been built by Prisma and its community
- [`Shared Prisma Client extensions`](https://www.prisma.io/docs/orm/prisma-client/client-extensions/shared-extensions): Share extensions or import shared extensions into your Prisma project