Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds the ability to keep specific fields raw when inserting and updating #59

Closed
wants to merge 1 commit into from

Conversation

brianherbert
Copy link
Contributor

Usage on INSERT:

$location = ORM::for_table('locations')->create();
$location->keep_raw('lat_lon');
$location->fsq_venue_id = $fsq_venue_id;
$location->lat_lon = "GeomFromText('POINT($lat $lon)')";
$location->name = $name;
$location->save();

Usage on UPDATE:

$location = ORM::for_table('locations')->find_one($location->id());
$location->keep_raw('lat_lon');
$location->lat_lon = "GeomFromText('POINT(1.2347 2.3436)')";
$location->name = 'modified name';
$location->save();

The keep_raw() function allows you to use special functionality provided by MySQL (and other DBs compatible with Idiorm) without forcing the developer to write a raw query. Of course it's still up to the developer to validate and protect themselves when using any raw functionality but this make code much cleaner and easier to read.

There's a new variable in the ORM class, $_keep_raw which holds a list of column names that the dev wants to keep raw. This is used in building placeholders (used by inserts) and when building updates directly. It's also used in save() to determine which variables to prepare.

@treffynnon
Copy link
Collaborator

This is a possible solution to issue #43

treffynnon added a commit that referenced this pull request Nov 12, 2012
@treffynnon
Copy link
Collaborator

@brianherbert thank you for submitting this patch to idiorm.

Unfortunately this patch will not be merged directly into idiorm, but it has inspired a very similar feature in commit: 004bfac

So thank you for the code and inspiration!

@treffynnon treffynnon closed this Nov 12, 2012
@brianherbert
Copy link
Contributor Author

Sweetness! Thanks for the continued support of Idiorm :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants