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
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 dereurom...@googlemail.com wrote:
i am
Perfect, thanks for that.
On Apr 21, 7:08 pm, Andy Dirnberger andy.dirnber...@gmail.com 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 =
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?
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
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
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
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 andy.dirnber...@gmail.com
wrote:
My example does not compare field1 and field2 for uniqueness against
each other, it compares field1 and field2
Is there a way in a model to verify that a record does not exist
already that matches a certain criteria. In the database table are
three columns: id, list_id and product_id. I would like to be able to
tell if there already exists a record with the same list_id AND
product_id as the one being
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];
10 matches
Mail list logo