Lithium PHP Framework - SQL Insert Ignore / If not exists

282 views Asked by At

is there any way to execute Lithium Model::save() functions with INSERT IGNORE and/or IF NOT EXISTS statements?

The only way to do so is executing RAW-SQL-Statements. But this would be a design violation...so any help would be great.

Thanks in advise.

/creality

1

There are 1 answers

0
captain geek On

There isn't a way to do that with Lithium unless you do the raw SQL. You can see that only "INSERT INTO ..." is supported with the lithium\data\source\Database object.

The reason that this isn't supported is that saving a new object will automatically populate the primary key (id) of the object and an INSERT IGNORE would really complicate the issue.

The best strategy is to run a SELECT based on the key values and then toss out any values that have matching records.