spadefoot / kohana-orm-leap

An ORM module for the Kohana PHP framework that is designed to work with all major databases.
http://spadefoot.github.io/kohana-orm-leap/
100 stars 25 forks source link

Can't use expressions anymore because of Kohana_BadData_Exception #59

Closed taai closed 12 years ago

taai commented 12 years ago

Now, when there is this this validation check built in, I can't use expressions anymore.

<?php
// "purchased" is field of DB_ORM_Field_DateTime
$car->purchased = DB_SQL::expr('now()');

This does throw an Kohana_BadData_Exception exception, because my expression doesn't pass DB_ORM_Field_DateTime built in validation.

If I can't use expressions, the Leap get's useless.

Possible solutions

In the validation there should check if the value is instanceof DB_SQL_Expression and if so, pass the validation, don't check anything. Also this has to do with __set() where should be checked if the value is an expression and if it is, don't do the settype().

Actually this gets more complicated! If you use expressions, you must save the model by setting the first (and only) argument $reload to TRUE:

<php
$car->save(TRUE);

In that way the model will get reloaded from the database. This must be done because the expressions that will get executed, but for normal save() the values will be what you set them with - the expressions. So, also in the save() method, there must be a instanceof check to set $reload = TRUE; automatically, if one of the values is an expression.

Discussion

I know that you all have things to do and you can't spend much time to all projects, that's why we collaborate to develop projects together. I want to know - what things I'm allowed to change? I have these ideas, but I don't want to code things, that you will discard, so I have to know what is the idea of Leap's structure. Can we have a Skype chat about the structure? Otherways I'm alone with my thoughts here.

bluesnowman commented 12 years ago

If you can, send us an email to spadefoot.oss@gmail.com and then we will send you our Skype username to chat.

bluesnowman commented 12 years ago

As for your ideas, they are great. Your contributions are highly considered and we are very happy to implement them.