Doctrine2验证是否修改了属性

I am building a bundle for uploading many photos.

I use a table to display my photo's forms.

visual of web page

My problem is, when I click on "Modifier" nothing is done if I didn't change "Activé" or "Titre".

public function ajaxEditPhotoAction(Request $request, $id) {
    $error = null;
    $em = $this->getDoctrine()->getManager();

    $repository = $em->getRepository("FDMFileUploaderBundle:Photo");
    $photo = $repository->find($id);
    $form = $this->get('form.factory')->create(new PhotoType(), $photo);

    if ($request->isMethod('POST')) {
        $form->bind($request);
        if ($form->isValid()) {
            $em->flush();
        }
        else {
            $error = "Mauvaise donnée";
        }
    }
    else {
        $error = "Wrong Method";
    }

    return $this->render('FDMFileUploaderBundle:Default:editPhoto.html.twig', array(
        "error" => $error
        )
    );
}

If I had this line after isValid(), that's work but when "Activé" or "Titre" are changed, my photos are uploaded twice.

$photo->upload();

How I can force an upload if my attribute which are persisted in my entity are not changed?

I have taken a look in doctrine annotation but, I didn't find solution.

Ajax submit

var data = new FormData(this);
$.ajax({
    type: "POST",
    url: url,
    data: data,
    contentType: false,
    cache: false,
    processData:false,
    success: function(data) {
        alert("Success");
    },
    error: function(xhr, textStatus, errorThrown) {
        alert("Error "+xhr+textStatus+errorThrown);
    }
});

You can check if your $request have files inside. This will do the trick.

if ($form->isValid() || $request->files->count() > 0) {
        $photo->upload();
        $em->flush();
    }

Edit by olive007:

Thank you help I have found my solution:

$nbFile = $request->files->count();

if ($form->isValid()) {
    $uow = $em->getUnitOfWork();
    $uow->computeChangeSets();
    if ($nbFile == 1 && !$uow->isScheduledForUpdate($photo)) {
        // title and enabled aren't modified but file is
        $photo->upload();
    }
    else {
        $em->flush();
    }
}