Asked  8 Months ago    Answers:  5   Viewed   33 times

I am developing my application using Zend Framework 2 and Doctrine 2.

While writting annotations, I am unable to understand the difference between mappedBy and inversedBy.

When should I use mappedBy?

When should I use inversedBy?

When should I use neither?

Here is an example:

 * @ORMOneToOne(targetEntity="custModEntityPerson", mappedBy="customer")
 * @ORMJoinColumn(name="personID", referencedColumnName="id")
protected $person;

 * @ORMOneToOne(targetEntity="AuthEntityUser")
 * @ORMJoinColumn(name="userID", referencedColumnName="id")
protected $user;

 * @ORMManyToOne (targetEntity="custModEntityCompany", inversedBy="customer")
 * @ORMJoinColumn (name="companyID", referencedColumnName="id")
protected $company;

I did a quick search and found the following, but I am still confused:

  • example 1
  • example 2
  • example 3


  • mappedBy has to be specified on the inversed side of a (bidirectional) association
  • inversedBy has to be specified on the owning side of a (bidirectional) association

from doctrine documentation:

  • ManyToOne is always the owning side of a bidirectional assocation.
  • OneToMany is always the inverse side of a bidirectional assocation.
  • The owning side of a OneToOne assocation is the entity with the table containing the foreign key.


Wednesday, March 31, 2021
answered 8 Months ago

$ app/console help doctrine:fixtures:load

By default Doctrine Data Fixtures uses DELETE statements to drop the existing rows from the database. If you want to use a TRUNCATE statement instead you can use the --purge-with-truncate flag:

./app/console doctrine:fixtures:load --purge-with-truncate

Truncate will reset the auto increments.


The console command is for Symfony, but it should be the same using Doctrine only:

./bin/doctrine orm:fixtures:load --purge-with-truncate

UPDATE #2 for the comment about throwing an exception

If you have foreign keys, you can only reset the AUTO_INCREMENT through regular SQL:

$connection = $this->getEntityManager()->getConnection();
$connection->exec("ALTER TABLE <tablename> AUTO_INCREMENT = 1;");
Saturday, May 29, 2021
answered 5 Months ago

The date() function returns a string. The datetime type works with DateTime objects. So either change the mapping type to string or use DateTime objects.

Thursday, July 29, 2021
answered 3 Months ago
  • colorPrimary – The color of the app bar.
  • colorPrimaryDark – The color of the status bar and contextual app bars; this is normally a dark version of colorPrimary.
  • colorAccent – The color of UI controls such as check boxes, radio buttons, and edit text boxes.
  • windowBackground – The color of the screen background.
  • textColorPrimary – The color of UI text in the app bar.
  • statusBarColor – The color of the status bar.
  • navigationBarColor – The color of the navigation bar.

you can use following link to setup your style.

Sunday, August 8, 2021
answered 3 Months ago

There are two key differences:

First, attributes assigned to a view via style will apply only to that view, while attributes assigned to it via android:theme will apply to that view as well as all of its children. For example, consider this style resource:

<style name="my_background">
    <item name="android:background">@drawable/gradient</item>

If we apply it to a LinearLayout with three child TextViews by using style="@style/my_background", then the linearlayout will draw with a gradient background, but the backgrounds of the textviews will be unchanged.

If instead we apply it to the LinearLayout using android:theme="@style/my_background" then the linearlayout and each of the three textviews will all use the gradient for their background.

The second key difference is that some attributes only affect views if they are defined in that view's theme. For example, consider this style resource:

<style name="checkboxes">
    <item name="colorAccent">#caf</item>
    <item name="colorControlNormal">#caf</item>

If I apply this to a CheckBox using style="@style/checkboxes", nothing will happen. If instead I apply it using android:theme="@style/checkboxes", the color of the checkbox will change.

Just like the first rule said, styles containing theme attributes will apply to all children of the view with the android:theme attribute. So I can change the color of all checkboxes in a linearlayout by applying android:theme="@style/checkboxes" to my linearlayout.

Sunday, August 22, 2021
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :