doctrine owning side and inverse side

owning and inverse side can be confusing. Then there is uni and bi directional relationships.

For example:

    /**
     * @ORM\ManyToMany(targetEntity="\Acme\UserBundle\Entity\User", inversedBy="users")
     * @ORM\JoinTable(
     *     name="gallery_has_users",
     *     joinColumns={@ORM\JoinColumn(name="gallery_id", referencedColumnName="id", nullable=false)},
     *     inverseJoinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)}
     * )
     */
    private $users;

These are some key rules:

* The owning side has to use the inversedBy attribute of the OneToOne, ManyToOne, or ManyToMany mapping declaration. The inversedBy attribute contains the name of the association-field on the inverse-side.

* The inverse side has to use the mappedBy attribute of the OneToOne, OneToMany, or ManyToMany mapping declaration. The mappedBy attribute contains the name of the association-field on the owning side.

* ManyToOne is always the owning side of a bidirectional association.

* OneToMany is always the inverse side of a bidirectional association.

* The owning side of a OneToOne association is the entity with the table containing the foreign key.

* You can pick the owning side of a many-to-many association yourself.

How do you decide on the owning side?

This sentence helps:

Entity A(Owning) has Entity B(inverse).
If I delete Entity A, I want to delete Entity B.

Doctrine will only check the owning side of an association for changes.

refer to doctrine site for more info.

http://doctrine-orm.readthedocs.org/en/latest/reference/unitofwork-associations.html

http://doctrine-orm.readthedocs.org/en/latest/reference/association-mapping.html

Form by_reference = true

if you are extending an entity, most of the time, you can ignore the by_reference field option. This is because it is set to true by default and its usually what you want.

for example

$formMapper->add('owner', 'entity', array(
                'class' => 'YourBundle:User',
                'multiple' => false,
                'required' => true,
                'label' => 'Gallery Owner'
                ))

This form field uses the variable “owner” as defined in the user class. it will call setOwner in the user class when the form is submitted before saving into the db.

Setting by_reference to false forces the framework to call the setter on the parent object instead. Since you are extending the parent entity, most of the time, you don’t want to touch the parent entity.

Useful tools in chrome

chrome can be a really cool tool, not just a browser. Some cools extensions are:

qsnap – for capturing and annotating screenshots.
markdown viewer – for viewing markdown and auto refreshing if there are changes.

Install drush in cpanel

* you will need root access to the server

cd /usr/local/bin
wget https://github.com/drush-ops/drush/archive/master.zip
unzip master.zip
rm master.zip
ln -s drush-master/drush drush
cd drush-master
composer install

If composer fails, it is most likely you dont have some extensions. If using cpanel,

# we will need to recompile
echo "--enable-pcntl" >> /var/cpanel/easy/apache/rawopts/all_php5
echo "--with-readline" >> /var/cpanel/easy/apache/rawopts/all_php5

# Now go to whm, easyapache and recompile
# once done you should see the extension being listed with this command line
php -m | grep pcntl

If all is working “drush core-status” should be working

Cleaning up git history with git rebase

Git rebase is good when you want to combine some historical commits into one commit. This might be a good idea because your history contains too many unncessary test commits, or if you want to cut down the size of your git objects. On the other hand, changing history can be a dangerous thing, it means that everyone else using your repo needs to acknowledge the change by force pulling.

for example,

git log --oneline
291423b update setup
7732e24 update deployment files
5e0c60f Merge branch 'develop'
e656609 update paths
1f35b9a Merge branch 'develop'
c914ca6 update prod
746eff5 update readme
8754887 update readme
ce9563d update staging

Now we want to remove everything between 291423b and ce9563d. Basically, you want to crunch everything from 291423b down to a point in history, ie ce9563d. Here comes rebase.

git rebase -i ce9563d
pick 8c79382 update
pick 8754887 update readme
pick 746eff5 update readme
pick c914ca6 update prod
pick e656609 update paths
pick 7732e24 update deployment files
pick 291423b update setup

# Rebase ce9563d..cd268a9 onto ce9563d
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

Note that now the latest commit is at the bottom, exactly reverse of what you see in git log. If you delete any of the lines, the commit will be gone. This is a bad bad idea and its best not to do that, instead, use “f” or ‘s’ and leave the first commit as it is like so:

pick 8c79382 update
f 8754887 update readme
f 746eff5 update readme
f c914ca6 update prod
f e656609 update paths
f 7732e24 update deployment files
f 291423b update setup

# Rebase ce9563d..cd268a9 onto ce9563d
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

rebase will tell you if it encounters any problems. Fix them and you have to force push

git push origin --force

bursa escort bayan


Selam ben Yildirim escort Ayse Butun yorgunlugunuzu alip siradan hayatinizi canlandiracak
zihninizi butunescort bursa bayanlari
escort mugla bayan
tekirdag escort ilanlari
olumsuzluklardan arindirip hayati size daha pozitif ve olumlu yasatacak buyulu bir elin sizi bu karanlik dunyadan
kurtaracagi ani hala bekliyorsaniz buna artik son vermenizin
zamani geldi hemen simdi beni arayarak monoton yasantiniza
bir geceligine ara verip kendinizi yenilenmis hissedecek ve benden

Escort bayanlar seni bekliyor

Simple way to redirect user if Mobile

Javascript can detect screen size and redirect users if they are using mobile. I’ve found that checking the screen size and redirecting users based on that can cover 99% of the use cases rather than injecting some complicated browser detection javascript libraries.

The screen width of IPAD is 768px and screen width of a bigger mobile is 500px. So it would be safe to say that you anyone browsing the site using mobile phone would have a resolution lesser than 700px.

A simple script like that will work

if (screen.width <= 700) {
  window.location = "http://your-mobile-site";
}

The most time consuming part of software development process

People seem to think that the most time consuming and tedious part of developing a software is the coding of the software. This is wrong.

The most tedious process is to get the right requirements for the project. Good business requirements without loopholes give good boundary of how the software will evolve. Screenshots and user journeys are really important. People seem to underestimate the importance of this beginning step, leading to scope creep while developing the software.

You can outsource coding but you cannot outsource requirements gathering. You cannot outsource the relationship with your client.

People say “we are agile now”, why are we still taking so long to develop a bug free software? You have the answer yourself.