PHPackages                             gollumsf/entity-relation-setter - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. gollumsf/entity-relation-setter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

gollumsf/entity-relation-setter
===============================

Trait for add method cross setter

v3.0.0(1mo ago)31.1k1GPL-3.0-or-laterPHPPHP &gt;=8.2CI failing

Since Dec 6Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/GollumSF/entity-relation-setter)[ Packagist](https://packagist.org/packages/gollumsf/entity-relation-setter)[ Docs](https://github.com/GollumSF/eentity-relation-setter)[ RSS](/packages/gollumsf-entity-relation-setter/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (8)Dependencies (6)Versions (9)Used By (1)

EntityRelationSetter
====================

[](#entityrelationsetter)

[![Build Status](https://github.com/GollumSF/entity-relation-setter/actions/workflows/doctrine_2.10.yml/badge.svg?branch=master)](https://github.com/GollumSF/entity-relation-setter/actions)[![Build Status](https://github.com/GollumSF/entity-relation-setter/actions/workflows/doctrine_2.11.yml/badge.svg?branch=master)](https://github.com/GollumSF/entity-relation-setter/actions)[![Build Status](https://github.com/GollumSF/entity-relation-setter/actions/workflows/doctrine_3.0.yml/badge.svg?branch=master)](https://github.com/GollumSF/entity-relation-setter/actions)[![Build Status](https://github.com/GollumSF/entity-relation-setter/actions/workflows/doctrine_latest.yml/badge.svg?branch=master)](https://github.com/GollumSF/entity-relation-setter/actions)

[![Coverage](https://camo.githubusercontent.com/233b7de8022a663c16347feea4e254acd992f96f082f78a1ea8ffa57caa4925b/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f476f6c6c756d53462f656e746974792d72656c6174696f6e2d7365747465722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/GollumSF/entity-relation-setter)[![License](https://camo.githubusercontent.com/6540dd526b55fb9dd75fd6798a9ff4e0fbb93f2625a2c0462a3db9bf464a77f8/68747470733a2f2f706f7365722e707567782e6f72672f676f6c6c756d73662f656e746974792d72656c6174696f6e2d7365747465722f6c6963656e7365)](https://packagist.org/packages/gollumsf/entity-relation-setter)[![Latest Stable Version](https://camo.githubusercontent.com/20fae0aa9d7719723a5c264586f048f960823b744781e566ebec49611d6fb5a5/68747470733a2f2f706f7365722e707567782e6f72672f676f6c6c756d73662f656e746974792d72656c6174696f6e2d7365747465722f762f737461626c65)](https://packagist.org/packages/gollumsf/entity-relation-setter)[![Latest Unstable Version](https://camo.githubusercontent.com/bb7a425e4124be28772698c122df943a62e590ebb3c41287f68c5872c3efb5af/68747470733a2f2f706f7365722e707567782e6f72672f676f6c6c756d73662f656e746974792d72656c6174696f6e2d7365747465722f762f756e737461626c65)](https://packagist.org/packages/gollumsf/entity-relation-setter)[![Discord](https://camo.githubusercontent.com/e2ea9d7fb91494f17c7c76925e006e2ad2d7586fa54f500364bddda1520eecb1/68747470733a2f2f696d672e736869656c64732e696f2f646973636f72642f3637313734313934343134393537333638373f636f6c6f723d707572706c65266c6162656c3d646973636f7264)](https://discord.gg/xMBc5SQ)

Trait for add method cross setter

Installation:
-------------

[](#installation)

```
composer require gollumsf/entity-relation-setter
```

Exemple
-------

[](#exemple)

### OneToOne

[](#onetoone)

```
use GollumSF\EntityRelationSetter\OneToOneSetter;

class User {

	use OneToOneSetter;

	/**
	 * @ORM\OneToOne(targetEntity=Address::class, inversedBy="tiers")
	 * @var Address
	 */
	private $address;

	////////////
	// Setter //
	////////////

	public function setAddress(?Address $address): self {
		return $this->oneToOneSet($address/*, 'address', 'user'*/);
	}
}

class Address {

	use OneToOneSetter;

	/**
	 * @ORM\OneToOne(targetEntity=Tiers::User, mappedBy="address")
	 * @var Address
	 */
	private $address;

	////////////
	// Setter //
	////////////

	public function setUser(?User $user): self {
		return $this->oneToOneSet($user/*, 'user', 'address'*/);
	}
}
```

### OneToManySetter and ManyToOneSetter

[](#onetomanysetter-and-manytoonesetter)

```
use GollumSF\EntityRelationSetter\ManyToOneSetter;
use GollumSF\EntityRelationSetter\OneToManySetter;

class Address {

	use ManyToOneSetter;

	/**
	 * @ORM\ManyToOne(targetEntity=Country::class, inversedBy="addresses")
	 * @var Country
	 */
	private $country;

	////////////
	// Setter //
	////////////

	public function setCountry(?Country $country): self {
		return $this->manyToOneSet($country/*, 'country', 'address'*/);
	}
}

class Country {

	use OneToManySetter;

	/**
	 * @ORM\OneToMany(targetEntity=Address::class, mappedBy="country")
	 * @var Address[]|ArrayCollection
	 */
	private $addresses;

	public function __construct() {
		$this->addresses = new ArrayCollection();
	}

	/////////
	// Add //
	/////////

	public function addAddress(Address $address): self {
		return $this->oneToManyAdd($address/*, 'addresses', 'country'*/);
	}

	////////////
	// Remove //
	////////////

	public function removeAddress(Address $address): self {
		return $this->oneToManyRemove($address/*, 'addresses', 'country'*/);
	}
}
```

### ManyToManySetter

[](#manytomanysetter)

```
use GollumSF\EntityRelationSetter\ManyToManySetter;

class Post {

	use ManyToManySetter;

	/**
	 * @ORM\ManyToMany(targetEntity=Tag::class, inversedBy="posts")
	 * @var Tag[]|ArrayCollection
	 */
	private $tags;

	public function __construct() {
		$this->tags = new ArrayCollection();
	}

	/////////
	// Add //
	/////////

	public function addTag(Tag $tag): self {
		return $this->manyToManyAdd($tag/*, 'tags', 'post'*/);
	}

	////////////
	// Remove //
	////////////

	public function removeTag(Tag $tag): self {
		return $this->manyToManyRemove($tag/*, 'tags', 'post'*/);
	}
}

class Tag {

	use ManyToManySetter;

	/**
	 * @ORM\ManyToMany(targetEntity=Post:class, inversedBy="tags")²&
	 * @var Post[]|ArrayCollection
	 */
	private $posts;

	public function __construct() {
		$this->posts = new ArrayCollection();
	}

	/////////
	// Add //
	/////////

	public function addPost(Post $post): self {
		return $this->manyToManyAdd($post/*, 'posts', 'tag'*/);
	}

	////////////
	// Remove //
	////////////

	public function removePost(Post $post): self {
		return $this->manyToManyRemove($post/*, 'posts', 'tag'*/);
	}
}
```

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance90

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~328 days

Recently: every ~561 days

Total

8

Last Release

50d ago

Major Versions

v1.1.0 → v2.0.02020-01-31

v2.2.0 → v3.0.02026-03-24

PHP version history (3 changes)v1.0.0PHP &gt;=7.0

v2.0.0PHP &gt;=7.1

v3.0.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/6690bb36165854e1db86762d56c22351ff844b12f59e5c91993a6d793f098cfb?d=identicon)[Smeagolworms4](/maintainers/Smeagolworms4)

---

Top Contributors

[![Smeagolworms4](https://avatars.githubusercontent.com/u/4448640?v=4)](https://github.com/Smeagolworms4 "Smeagolworms4 (36 commits)")

---

Tags

entitysetterrelationgollumsf

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gollumsf-entity-relation-setter/health.svg)

```
[![Health](https://phpackages.com/badges/gollumsf-entity-relation-setter/health.svg)](https://phpackages.com/packages/gollumsf-entity-relation-setter)
```

###  Alternatives

[shapecode/hidden-entity-type-bundle

Hidden field for Symfony entities

28428.6k1](/packages/shapecode-hidden-entity-type-bundle)[smile/module-custom-entity

Smile - Custom Entity Module

36104.1k5](/packages/smile-module-custom-entity)

PHPackages © 2026

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