Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8517889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:49:50+00:00 2026-06-11T05:49:50+00:00

I have 3 Entities Users , UserProfile and Staffs The User profile is linked

  • 0

I have 3 Entities Users, UserProfile and Staffs

The User profile is linked to Users table through user id
The Staff table is linked to userprofile using the userprofileid

Admin create the user profile and generate the registration no, username and password.

I want add a user record to the users table then add the user profile and then add the profile id to the staff table.

I want to persist three entities sequentialy

I tried to create an instance for the Users like

$this->userent->setUsername('xxx');
$this->em->persist($this->userent);
$this->em->flush();

then:

$this->profileent->setFirstname('xxx');
$this->em->persist($this->profileent);
$this->em->flush();

Basically a form is shared among three entities and I want to insert into three tables sequentially,

Updated

Apart from users entity i have a usertype entity linked to users…i want to persist only the foreign key. i have

setUserType(Usertype $userType) method an instance of the user_type entity in users

when i do

 $this->userent = new Users();
$this->userent->setUserType($this->em->getRepository('\Campus\Entity\Usertype')->findByUserType("admin")) 

i get the error

Argument 1 passed to Campus\Entity\Users::setUserType() must be an instance of Campus\Entity\Usertype, array given

if i pass the value of the array which is an instance of Usertype

i get an error saying need an array for the ArrayCollection..help please!!!

Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::__construct() must be of the type array, object given, called in D:\xampp\htdocs\zend\library\Doctrine\ORM\UnitOfWork.php on line 406 defined in D:\xampp\htdocs\zend\library\Doctrine\Common\Collections\ArrayCollection.php on line 46
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:49:52+00:00Added an answer on June 11, 2026 at 5:49 am

    Think less about the database, and more about your objects. That’s the whole point of doctrine.

    You want something like this:

    <?php
    // create some entities
    
    $user = new Entity\User();
    $user->setUsername('userman');
    
    $profile = new Entity\UserProfile();
    $profile->setFirstname('joe');
    $profile->setLastname('smith');
    
    $staff = new Entity\Staff();
    $staff->setSomething('value-for-something');
    
    // associate those entities together
    $profile->setStaff($staff);
    $user->setProfile($profile);
    
    // assuming you have set up cascade={"persist"} on your associations
    $this->em->persist($user);
    
    // if you haven't set up cascade={"persist"}, you will need to call persist on each entity:
    // $this->em->persist($profile);
    // $this->em->persist($staff);
    
    $em->flush();
    

    So, the basic idea is you build up your objects, get them into Doctrine’s Unit-of-Work (by calling persist() and maybe having some cascades set up), then write them all to the database in a single transaction by calling flush()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an admin form that lets users create entities that require an image.
I have two entities. User and Role. I am using Devise and CanCan. They
I have 2 Entities User and User_Profile (one to one relationship). I have linked
I have two tables/entities Users and Companies . Both are linked m-n relationship. When
I have two entities, projects and users. These are modeled in Rails using Mongoid
I have two entities that represent users ( User ) and friendship requests (
I have entities Group and User . the Group entity has Users property which
I am using CodeFirst EntityFramework. I have a IQueryable<User> Entities that are returned using
Say I have a User and UserProfile entities. I'd like to be able to
I have two entities, a User and a UserProfile. The PK of User is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.