Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine/Symfony: Entity with non-mapped property

How can I add a property to an Entity Class, which should not be mapped to the database?

I need the property for a temporary value. Therefore the property should not be fetched from or persisted to the database. it neither should be a sql-calculated value, i need to set (and get) this within php code only.

like image 805
drummer23 Avatar asked Mar 17 '15 18:03

drummer23


1 Answers

Writing a property without annotation should not be linked to your Database as example of an entity User.

class User 
{
/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\Column(type="array")
 */
protected $username;

protected $notPersistedProperty

}

Hope this helped.

like image 113
Nawfal Serrar Avatar answered Oct 15 '22 14:10

Nawfal Serrar