Well, forget about that removing. Here is the problem:
I have a 'BannedEmail' entity with ONLY ONE property 'rule'. here is the
definition:


$metadata->setPrimaryTable(array(

  'name' => 'banned_emails',

   'uniqueConstraints' =>
   array(
'rule' => array(
    'columns' =>  array(
    0 => 'rule', ),
   ),
   ),
  ));

$metadata->mapField(array(

   'fieldName' => 'rule',

  'columnName' => 'rule',

   'type' => 'string',

   'nullable' => false,

   'length' => 60,

   'fixed' => false,

   'comment' => '',

   'default' => '',

   'id' => true,

));

I have method in the entity:


class BannedEmail {


private $rule;


    public function setRule($email)
    {

            $this->rule = $email;

    }


Now I am trying to persist:

$banned = new Entities\BannedEmail;

$banned->setRule($_POST['bannedEmails']);

$em->persist($banned);

$em->flush();

I get error:  Integrity constraint violation: 1048 Column 'rule' cannot be
null'
I tried to print debug inside setRule method and it works fine. This entity
has no mapping/association with any other entity? so what wrong I did? This
'rule' property is unique too. so should I add an incrementing id and use
'rule' as a normal property? or what wrong I did?




On Fri, Apr 18, 2014 at 7:38 PM, Herman Peeren <[email protected]>wrote:

> Still the code is nonsensical. Do you want to remove $bannedEmails from a
> $emails collection? Do you want to remove or add $emails from or to a
> $bannedEmails collection? First step is that it must be clear what you want
> to accomplish. Then you code it. Then you get error messages back. Then you
> look them up and correct your code. Then you eventually ask a question. If
> the question is not clear or not even what exactly you want to accomplish,
> the an answer cannot be given. Concrete names are often useful for easier
> communication.
>
>
>
> On Friday, 18 April 2014 16:37:03 UTC+2, Parsifal wrote:
>
>> by $blah I was just testing the code and if working, of course I use
>> better names in my script. I was just asking I am using a reasonable way to
>> do it or there is a better way?
>>
>>
>>
>>
>> On Fri, Apr 18, 2014 at 7:03 PM, Herman Peeren <[email protected]>wrote:
>>
>>> No, that is not correct, as you would have found out yourself if you try
>>> this code. Please do that first before you use as as a llokup-manual.
>>>
>>> Why do you use a remove() method of the entitymanager? What is that
>>> mentod doing? From what collection are you trying to remove that $email?
>>> What is $blah? An ORM helps us to use meaningful names.
>>>
>>>
>>> On Friday, 18 April 2014 16:18:03 UTC+2, Parsifal wrote:
>>>
>>>>
>>>> I wasn't ware of findAll() as I was looking wiki, found it on api then
>>>> using this:
>>>> $emails = $em->getRepository('Entities\BannedEmail')->findAll();
>>>> foreach ($emails as $email) {
>>>>          $blah = $em->remove($email);
>>>> }
>>>> $em->flush($blah);
>>>>
>>>> Am I in correct way to do so?
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Fri, Apr 18, 2014 at 6:31 PM, Herman Peeren <[email protected]>wrote:
>>>>
>>>>>  An ORM is to work with the objects and then, eventually persist some
>>>>> of that in a database. So you add, remove etc. emails from a collection
>>>>> (for instance of banned email adresses) and after being finished with a 
>>>>> set
>>>>> of transactions you can put it to a database. The problem you have here is
>>>>> mostly because you rare trying to operate on teh database directly. That 
>>>>> is
>>>>> much easier without an ORM. Why would you use Doctrine at all?
>>>>>
>>>>>
>>>>> On Friday, 18 April 2014 12:33:04 UTC+2, Parsifal wrote:
>>>>>>
>>>>>> I have an entity for BannedEmail, this has only one property 'email'.
>>>>>> In form this is separated by line, when submitted it should truncate
>>>>>> current table and exlode the submitted emails by '\n' then flush in 
>>>>>> foreach.
>>>>>>
>>>>>> 1) Should I certainly use dbal to truncate? or is there a way to emty
>>>>>> the table with ORM?
>>>>>>
>>>>>> 2) and when foreach the submitted data, flush() should be inside
>>>>>> foreach, or just persist should be inside foreach, and flush after 
>>>>>> foreach?
>>>>>> as this is per row, I guess each persist will ovverride the last one, so
>>>>>> flush must be inside foreach? right?
>>>>>>
>>>>>>
>>>>>>
>>>>>  --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "doctrine-user" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>> To post to this group, send email to [email protected].
>>>>>
>>>>> Visit this group at http://groups.google.com/group/doctrine-user.
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "doctrine-user" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at http://groups.google.com/group/doctrine-user.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "doctrine-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/doctrine-user.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to