[symfony-users] Re: sfValidatorPropelUnique fails on updates - 1.2

2009-11-16 Thread Richtermeister

Hey Stefan,

The initial form knows whether it's new or an update, because you give
it a concrete object into the constructor, and most likely you have
retrieved this object by its primary key before, so it's fully
populated.

If sending the pk via hidden input rubs anybody wrong, you don't have
to do it this way, as long as you ensure that you have a different way
to provide the form with the appropriate object to update. Some people
use the session for this, but that can be tricky, because users can
have multiple interfaces open, and a central session wouldn't know
which interface was editing which object, unless the primary key is
submitted as part of the form.
So, in reality its easier to keep it in there.

Cheers,
Daniel



On Nov 12, 2:58 am, Stefan Paschke  wrote:
> Hi
>
> I just ran into the same problem, and while I found the solution in
> this discussion, I think it is not clear enough, so let me repeat
> briefly, in case anyone comes across this in the future:
>
> like Richtermeister says, the problem can be solved by adding a
> _uniques key to the schema, and using the auto-generated from. If you
> do not want to do this, for some reason, you need to add the primary
> key of the model to the from as a hidden field, if you are using it
> for update actions, like this:
>
>     $this->setWidgetSchema(
>       new sfWidgetFormSchema(
>         array(
>           "id" => new sfWidgetFormInputHidden(),
>           ...
>         )
>       )
>     );
>
> and:
>
>     $this->setValidators(
>       array(
>         "id" => new sfValidatorPropelChoice( array( "model" =>
> "Member", "column" => "id", "required" => false ) ),
>       )
>     );
>
> so basically you are passing the primary key as a hidden value. This
> seems odd, because the form will know the difference between insert
> and update and behave correctly without doing this, yet somehow the
> sfValidatorPropelUnique doesn't.
>
> best wishes
>
> Stefan
>
> > On Sep 12, 7:09 pm, Richtermeister  wrote:
>
> > > Hey Ben,
>
> > > no, your first version is right. You only need to pass model and
> > > column.
> > > The object that your form is updating needs to have a primary key set
> > > though, in order to be considered anupdate. otherwise it will be
> > > considered new and theupdatewill fail.
>
> > > In the most basic propel form setup none of this should be an issue,
> > > since auto-generated forms are doing this just fine by themselves. Try
> > > adding a _uniques: key to the schema and add your field there, this
> > > will build the post validator straight into your base form.
>
> > > Or post your entire configure/setup function if nothing else helps :)
>
> > > Have a great day,
> > > Daniel
> > > > > > On Mar 11, 3:50 am, Benjamin  wrote:
>
> > > > > > > The code is below.  I have been searching for hours.  This is 
> > > > > > > failing
> > > > > > > on updates, saying that the user name has already been taken.  
> > > > > > > It's
> > > > > > > being used as a post validator.
>
> > > > > > > newsfValidatorPropelUnique(
> > > > > > >     array(
> > > > > > >         'model'         => 'Members',
> > > > > > >         'column'        => array('user_name'),
> > > > > > >     ),
> > > > > > >     array(
> > > > > > >         'invalid'       => 'This user name has already been 
> > > > > > > taken',
> > > > > > >     )),
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~--~~~~--~~--~--~---



[symfony-users] Re: sfValidatorPropelUnique fails on updates - 1.2

2009-11-16 Thread Stefan Paschke

Hi

I just ran into the same problem, and while I found the solution in
this discussion, I think it is not clear enough, so let me repeat
briefly, in case anyone comes across this in the future:

like Richtermeister says, the problem can be solved by adding a
_uniques key to the schema, and using the auto-generated from. If you
do not want to do this, for some reason, you need to add the primary
key of the model to the from as a hidden field, if you are using it
for update actions, like this:

$this->setWidgetSchema(
  new sfWidgetFormSchema(
array(
  "id" => new sfWidgetFormInputHidden(),
  ...
)
  )
);

and:

$this->setValidators(
  array(
"id" => new sfValidatorPropelChoice( array( "model" =>
"Member", "column" => "id", "required" => false ) ),
  )
);

so basically you are passing the primary key as a hidden value. This
seems odd, because the form will know the difference between insert
and update and behave correctly without doing this, yet somehow the
sfValidatorPropelUnique doesn't.

best wishes

Stefan


> On Sep 12, 7:09 pm, Richtermeister  wrote:
>
> > Hey Ben,
>
> > no, your first version is right. You only need to pass model and
> > column.
> > The object that your form is updating needs to have a primary key set
> > though, in order to be considered anupdate. otherwise it will be
> > considered new and theupdatewill fail.
>
> > In the most basic propel form setup none of this should be an issue,
> > since auto-generated forms are doing this just fine by themselves. Try
> > adding a _uniques: key to the schema and add your field there, this
> > will build the post validator straight into your base form.
>
> > Or post your entire configure/setup function if nothing else helps :)
>
> > Have a great day,
> > Daniel
> > > > > On Mar 11, 3:50 am, Benjamin  wrote:
>
> > > > > > The code is below.  I have been searching for hours.  This is 
> > > > > > failing
> > > > > > on updates, saying that the user name has already been taken.  It's
> > > > > > being used as a post validator.
>
> > > > > > newsfValidatorPropelUnique(
> > > > > >     array(
> > > > > >         'model'         => 'Members',
> > > > > >         'column'        => array('user_name'),
> > > > > >     ),
> > > > > >     array(
> > > > > >         'invalid'       => 'This user name has already been taken',
> > > > > >     )),

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~--~~~~--~~--~--~---



[symfony-users] Re: sfValidatorPropelUnique fails on updates - 1.2

2009-09-27 Thread pomidor

Hi,

I had the same problem
My solution is to create custom validator inherited from
sfValidatorPropelUnique wich accepts 'criteia' object as an option
it allows to set NOT_EQUAL criteria for my instance id in validator
when editing

Best wishes,

Yuriy

On Sep 12, 7:09 pm, Richtermeister  wrote:
> Hey Ben,
>
> no, your first version is right. You only need to pass model and
> column.
> The object that your form is updating needs to have a primary key set
> though, in order to be considered an update. otherwise it will be
> considered new and the update will fail.
>
> In the most basic propel form setup none of this should be an issue,
> since auto-generated forms are doing this just fine by themselves. Try
> adding a _uniques: key to the schema and add your field there, this
> will build the post validator straight into your base form.
>
> Or post your entire configure/setup function if nothing else helps :)
>
> Have a great day,
> Daniel
>
> On Sep 11, 6:26 pm, Matías López  wrote:> Hello..
>
> > I had this issue.. you need to put in the primary_key the field that is
> > unique.
>
> > In this case: 'primary_key' => 'user_name'
>
> > Rgds,
>
> > Lic. Matías López
> > E-mail: lopezmat...@gmail.com
> > Movil: +54 9 341 155 799291
>
> > On Wed, Mar 11, 2009 at 10:49 PM, Benjamin  wrote:
>
> > > I spoke too soon.  Now it allows you to create multiple entries with
> > > the same user name.  I've spent about 12 hours researching this, I
> > > read the form book, looked through all the tutorials, looked at the
> > > api documentation and search good for hours.  Can someone please for
> > > the love of god help me figure out how to get this validator to work
> > > right?
>
> > > On Mar 11, 5:24 pm, Benjamin  wrote:
> > > > I'm going to leave this up in case anyone else has the same problem.
> > > > The answer is that you must specify the primary key, if the unique
> > > > field is not the primary key.  Here is a working example:
>
> > > > [code=php]
> > > > new sfValidatorPropelUnique(
> > > >     array(
> > > >         'model'         => 'Members',
> > > >         'column'        => array('user_name', 'id'),
> > > >     ),
> > > >     array(
> > > >         'invalid'       => 'This user name has already been taken',
> > > >     )
> > > > ),
> > > >  [/code]
>
> > > > On Mar 11, 3:50 am, Benjamin  wrote:
>
> > > > > The code is below.  I have been searching for hours.  This is failing
> > > > > on updates, saying that the user name has already been taken.  It's
> > > > > being used as a post validator.
>
> > > > > new sfValidatorPropelUnique(
> > > > >     array(
> > > > >         'model'         => 'Members',
> > > > >         'column'        => array('user_name'),
> > > > >     ),
> > > > >     array(
> > > > >         'invalid'       => 'This user name has already been taken',
> > > > >     )),
>
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~--~~~~--~~--~--~---



[symfony-users] Re: sfValidatorPropelUnique fails on updates - 1.2

2009-09-12 Thread Richtermeister

Hey Ben,

no, your first version is right. You only need to pass model and
column.
The object that your form is updating needs to have a primary key set
though, in order to be considered an update. otherwise it will be
considered new and the update will fail.

In the most basic propel form setup none of this should be an issue,
since auto-generated forms are doing this just fine by themselves. Try
adding a _uniques: key to the schema and add your field there, this
will build the post validator straight into your base form.

Or post your entire configure/setup function if nothing else helps :)

Have a great day,
Daniel




On Sep 11, 6:26 pm, Matías López  wrote:
> Hello..
>
> I had this issue.. you need to put in the primary_key the field that is
> unique.
>
> In this case: 'primary_key' => 'user_name'
>
> Rgds,
>
> Lic. Matías López
> E-mail: lopezmat...@gmail.com
> Movil: +54 9 341 155 799291
>
> On Wed, Mar 11, 2009 at 10:49 PM, Benjamin  wrote:
>
> > I spoke too soon.  Now it allows you to create multiple entries with
> > the same user name.  I've spent about 12 hours researching this, I
> > read the form book, looked through all the tutorials, looked at the
> > api documentation and search good for hours.  Can someone please for
> > the love of god help me figure out how to get this validator to work
> > right?
>
> > On Mar 11, 5:24 pm, Benjamin  wrote:
> > > I'm going to leave this up in case anyone else has the same problem.
> > > The answer is that you must specify the primary key, if the unique
> > > field is not the primary key.  Here is a working example:
>
> > > [code=php]
> > > new sfValidatorPropelUnique(
> > >     array(
> > >         'model'         => 'Members',
> > >         'column'        => array('user_name', 'id'),
> > >     ),
> > >     array(
> > >         'invalid'       => 'This user name has already been taken',
> > >     )
> > > ),
> > >  [/code]
>
> > > On Mar 11, 3:50 am, Benjamin  wrote:
>
> > > > The code is below.  I have been searching for hours.  This is failing
> > > > on updates, saying that the user name has already been taken.  It's
> > > > being used as a post validator.
>
> > > > new sfValidatorPropelUnique(
> > > >     array(
> > > >         'model'         => 'Members',
> > > >         'column'        => array('user_name'),
> > > >     ),
> > > >     array(
> > > >         'invalid'       => 'This user name has already been taken',
> > > >     )),
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~--~~~~--~~--~--~---



[symfony-users] Re: sfValidatorPropelUnique fails on updates - 1.2

2009-09-11 Thread Matías López
Hello..

I had this issue.. you need to put in the primary_key the field that is
unique.

In this case: 'primary_key' => 'user_name'

Rgds,

Lic. Matías López
E-mail: lopezmat...@gmail.com
Movil: +54 9 341 155 799291


On Wed, Mar 11, 2009 at 10:49 PM, Benjamin  wrote:

>
> I spoke too soon.  Now it allows you to create multiple entries with
> the same user name.  I've spent about 12 hours researching this, I
> read the form book, looked through all the tutorials, looked at the
> api documentation and search good for hours.  Can someone please for
> the love of god help me figure out how to get this validator to work
> right?
>
> On Mar 11, 5:24 pm, Benjamin  wrote:
> > I'm going to leave this up in case anyone else has the same problem.
> > The answer is that you must specify the primary key, if the unique
> > field is not the primary key.  Here is a working example:
> >
> > [code=php]
> > new sfValidatorPropelUnique(
> > array(
> > 'model' => 'Members',
> > 'column'=> array('user_name', 'id'),
> > ),
> > array(
> > 'invalid'   => 'This user name has already been taken',
> > )
> > ),
> >  [/code]
> >
> > On Mar 11, 3:50 am, Benjamin  wrote:
> >
> >
> >
> > > The code is below.  I have been searching for hours.  This is failing
> > > on updates, saying that the user name has already been taken.  It's
> > > being used as a post validator.
> >
> > > new sfValidatorPropelUnique(
> > > array(
> > > 'model' => 'Members',
> > > 'column'=> array('user_name'),
> > > ),
> > > array(
> > > 'invalid'   => 'This user name has already been taken',
> > > )),
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~--~~~~--~~--~--~---



[symfony-users] Re: sfValidatorPropelUnique fails on updates - 1.2

2009-03-11 Thread Benjamin

I spoke too soon.  Now it allows you to create multiple entries with
the same user name.  I've spent about 12 hours researching this, I
read the form book, looked through all the tutorials, looked at the
api documentation and search good for hours.  Can someone please for
the love of god help me figure out how to get this validator to work
right?

On Mar 11, 5:24 pm, Benjamin  wrote:
> I'm going to leave this up in case anyone else has the same problem.
> The answer is that you must specify the primary key, if the unique
> field is not the primary key.  Here is a working example:
>
> [code=php] 
> new sfValidatorPropelUnique(
>     array(
>         'model'         => 'Members',
>         'column'        => array('user_name', 'id'),
>     ),
>     array(
>         'invalid'       => 'This user name has already been taken',
>     )
> ),
>  [/code]
>
> On Mar 11, 3:50 am, Benjamin  wrote:
>
>
>
> > The code is below.  I have been searching for hours.  This is failing
> > on updates, saying that the user name has already been taken.  It's
> > being used as a post validator.
>
> > new sfValidatorPropelUnique(
> >     array(
> >         'model'         => 'Members',
> >         'column'        => array('user_name'),
> >     ),
> >     array(
> >         'invalid'       => 'This user name has already been taken',
> >     )),
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~--~~~~--~~--~--~---



[symfony-users] Re: sfValidatorPropelUnique fails on updates - 1.2

2009-03-11 Thread Benjamin

I'm going to leave this up in case anyone else has the same problem.
The answer is that you must specify the primary key, if the unique
field is not the primary key.  Here is a working example:

[code=php] 
new sfValidatorPropelUnique(
    array(
        'model'         => 'Members',
        'column'        => array('user_name', 'id'),
    ),
    array(
        'invalid'       => 'This user name has already been taken',
    )
),
 [/code]

On Mar 11, 3:50 am, Benjamin  wrote:
> The code is below.  I have been searching for hours.  This is failing
> on updates, saying that the user name has already been taken.  It's
> being used as a post validator.
>
> new sfValidatorPropelUnique(
>     array(
>         'model'         => 'Members',
>         'column'        => array('user_name'),
>     ),
>     array(
>         'invalid'       => 'This user name has already been taken',
>     )),
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~--~~~~--~~--~--~---