PHPackages                             geosocio/entity-attacher - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. geosocio/entity-attacher

ActiveLibrary[Database &amp; ORM](/categories/database)

geosocio/entity-attacher
========================

Utility to Attach Doctrine Entities to existing instances

1.0.6(8y ago)366211LGPL-3.0-onlyPHP

Since Jun 23Pushed 7y ago1 watchersCompare

[ Source](https://github.com/geosocio/entity-attacher)[ Packagist](https://packagist.org/packages/geosocio/entity-attacher)[ RSS](/packages/geosocio-entity-attacher/feed)WikiDiscussions develop Synced 3w ago

READMEChangelogDependencies (5)Versions (8)Used By (1)

Entity Attacher [![Build Status](https://camo.githubusercontent.com/a2e306ab94021f9a6dfdca764d24351d9cbe01c2c42162ef6ebd38158d8cf984/68747470733a2f2f7472617669732d63692e6f72672f67656f736f63696f2f656e746974792d61747461636865722e7376673f6272616e63683d646576656c6f70)](https://travis-ci.org/geosocio/entity-attacher) [![Coverage Status](https://camo.githubusercontent.com/561bc5affe223a8eba8efa8437ac34d622c6eb1d2b3b468889ac0173191e2264/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f67656f736f63696f2f656e746974792d61747461636865722f62616467652e737667)](https://coveralls.io/github/geosocio/entity-attacher)
==================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#entity-attacher--)

Provides a method to attach *related* entities to the current *unattached*entity.This library is the product of a missing API that was found in [doctrine/doctrine2#6459](https://github.com/doctrine/doctrine2/issues/6459). If you want to create a new entity with a lot of existing related entities, you would have to manually go through each relation and attach the related entities.

This can be tedious for entities that have a large number of relationships.

Configuration
-------------

[](#configuration)

Add something like this to your service configuration:

```
app.entity_attacher:
        class: GeoSocio\EntityAttacher\EntityAttacher
        arguments:
            - '@doctrine.orm.entity_manager'
            - '@annotations.reader'
```

You may also need to add the `GeoSocio\EntityAttacher\Annotation\Attach`annotation to your annotation reader.

Usage
-----

[](#usage)

Add the `@Attach` annotation to the relationships that *should* be attached.

```
/**
 * @ORM\Entity()
 * @ORM\Table(name="post")
 */
class Post
{

    /**
     * @ORM\ManyToOne(targetEntity="GeoSocio\Core\Entity\User\User")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="user_id")
     * @Attach()
     */
    private $user;
}
```

Then when a new `Post` is created, you can attach the entity:

```
$post = $this->attacher->attach($post);
```

Doing this will retrieve the `$user` from the database and prevent the `A new entity was found through the relationship` error. If you still receive that error, it means the `$user` was not found (and thus, should be persisted).

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 96.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~40 days

Recently: every ~59 days

Total

7

Last Release

3048d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e6fc8ba46d236d5a86fb070602b551af9b5d138de701e3254082eff4dbe6f201?d=identicon)[davidbarratt](/maintainers/davidbarratt)

---

Top Contributors

[![davidbarratt](https://avatars.githubusercontent.com/u/868364?v=4)](https://github.com/davidbarratt "davidbarratt (26 commits)")[![BenMorel](https://avatars.githubusercontent.com/u/1952838?v=4)](https://github.com/BenMorel "BenMorel (1 commits)")

---

Tags

doctrinedoctrine-ormphp

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/geosocio-entity-attacher/health.svg)

```
[![Health](https://phpackages.com/badges/geosocio-entity-attacher/health.svg)](https://phpackages.com/packages/geosocio-entity-attacher)
```

###  Alternatives

[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M196](/packages/sulu-sulu)[oro/platform

Business Application Platform (BAP)

642140.7k104](/packages/oro-platform)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1155.2k](/packages/rcsofttech-audit-trail-bundle)[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

6421.0M1](/packages/sonata-project-entity-audit-bundle)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9317.2k55](/packages/open-dxp-opendxp)[setono/doctrine-orm-batcher

A library for processing large collections in Doctrine

28650.9k7](/packages/setono-doctrine-orm-batcher)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
