0

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?

1 Answer 1

1

You should be doing something like:

$share->setBoards($boards);
3
  • I got call to undefined method, this one is really confusing me.
    – Naterade
    Aug 3, 2012 at 14:30
  • you have a property called boards. You should have a setter method for that property, which would be setBoards(). If you don't have it you should add it. Or you can use the doctrine: generate: entities command to have doctrine generate it for you. Aug 3, 2012 at 17:40
  • Carlos, you led me in the right direction. I had to use this $board = $em->getReference('PixbellyHomeBundle:Boards', $board_id); $share->setBoardId($board->getBoardId()); Lol, the problem is now it breaks my join statement, I can't win!
    – Naterade
    Aug 8, 2012 at 0:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.