Q:

Symfony2 cannot persist column that has a relationship

I have a Boards entity and a Shares entity. A board can have many shares( as in a user shared a board he made with another user).
The Boards entity has an auto inc. column called boardId. The shares entity has a column with the same name that maps a share to a board. Here is the code to map it:
Boards:
/**
 *  @orm:OneToMany(targetEntity="Shares", mappedBy="boards", cascade={"persist",  "remove"})
 */
private $shares;

Shares:
/**
 * @orm:ManyToOne(targetEntity="Boards", inversedBy="shares")
 * @orm:JoinColumns({
 *   @orm:JoinColumn(name="board_id", referencedColumnName="board_id")
 * })
 */
private $boards;

When I persist a new Share as so:
 $share = new Shares();
 $share->setMemberIdT($members[0]->getMemberId());
 $share->setMemberIdF($id);
 $share->setBoardId($boards[0]->getBoardId());
 $share->setDateShared();
 $share->setReceived(0);

I'm calling the boardId as so:
 $boards = $em->getRepository('PixbellyHomeBundle:Boards')
    ->findByBoardId($board);

I have echoed out the the boardId up until, literally, the line before and the id is correct, however when I call persist, I get this error:
"response":{"errorInfo":["23000",1048,"Column 'board_id' cannot be null"]}}

I think it has to do with the relationship but I have tried it all and nothing, any help?

A:

You should be doing something like:
$share->setBoards($boards);

