I again stand corrected :)
You are right!
My main concern was that the database already can provide this check
for duplicate records, so why code it!
Anyway, if Swanny is happy, then who am I to complain :D
Enjoy,
John
On Apr 23, 1:49 pm, euromark wrote:
> i am afraid you are wrong about tha
i am afraid you are wrong about that, john
(if i understand you right)
my method checks if a set of given data already exists in the db - and
if so, return a "duplicate content" error (if you add the appropriate
text message)
and instead of only one pair as the core function this can check on
mult
Sorry Andy,
It is just that your stripped down version doesn't show that :) I
stand corrected!
Enjoy,
John
On Apr 23, 12:55 am, Andy Dirnberger
wrote:
> My example does not compare field1 and field2 for uniqueness against
> each other, it compares field1 and field2 against the database. When
>
My example does not compare field1 and field2 for uniqueness against
each other, it compares field1 and field2 against the database. When
creating a new record, it will check that the combination of
field1+field2 doesn't already exist in the database. When updating a
record it will check that the c
Thanks Euromark,
I actually don't think that PHP code is the correct solution to this
check :) I think that the correct solution is to let the database
handle the unique check. The model will then be passed back the error
and will take action on it (by the code we write). Probably there
should be
i once wrote a app_helper method for this:
/**
* checks a record, if it is unique - depending on other fields in
this table (transfered as array)
* example in model: 'rule' => array
('uniqueRecord',array('belongs_to_table_id','some_id','user_id')),
* if all keys
What exactly is this validation supposed to validate?
1) That among the submitted data are no duplicate records (field1 +
field2)?
2) That among the submitted data and the existing records in the table
are no duplicate records?
>From what I see, the validation handles only no. 1). Is that correct?
Perfect, thanks for that.
On Apr 21, 7:08 pm, Andy Dirnberger wrote:
> Here's a stripped down example of how I do it:
>
> app_model.php
> class AppModel extends Model {
>
> ...
>
> function isUniqueMulti($data, $fields) {
> if (!is_array($fields)) {
> $fields = array($fields);
>
Here's a stripped down example of how I do it:
app_model.php
class AppModel extends Model {
...
function isUniqueMulti($data, $fields) {
if (!is_array($fields)) {
$fields = array($fields);
}
foreach ($fields as $key) {
$tmp[$key] = $this->data[$this->name][$key];