DataMapper ORM v1.8.2 |
[eluser]WanWizard[/eluser]
@pukrai, $this->db points to CI's driver. So something has changed $CI->db. Are you using a $this->load->database somewhere? Are you autoloading the database?
[eluser]WanWizard[/eluser]
@Tonko, You can either use SQL functions, or the same trick as you've used before: select('something complicated here', false). Datamapper mimics CI syntax as much as possible.
[eluser]pukrai[/eluser]
[quote author="WanWizard" date="1347817753"]@pukrai, $this->db points to CI's driver. So something has changed $CI->db. Are you using a $this->load->database somewhere? Are you autoloading the database?[/quote] I autoload database and datamapper. Your input did lead my hopefully into the right direction: Since I am switching from ion_auth to my library, some calls still direct to ion_auth and I am using quite some redirects in the login/registering process. Since ion_auth does a $this->load->database, that could have messed things up. This explains too, that the error did not occur everytime for every controller function call, I will keep you posted if you are interested if that really was the case. Feeling a little stupid if that really was the error since I wasted your precious time. Keep up the great work, Wan! Best regards, puk
[eluser]rick20[/eluser]
Hi @Wanwizard, first I wanna say thank you for your datamapper, it really helps a lot in my current project, I hope you still keep the good work I have a question I've asked before here: http://stackoverflow.com/questions/12453...after-save My problem is, I want to serialize() a field on my object when saving to the database and unserialize() it when getting from the database. In this case, I use 'rules' and 'get_rules' for that field. However, accessing the field value after calling save() method returns serialized value instead of unserialized one. So I have to re-get() the object to have 'get_rules' works for that field as suggested by Jordan Arseno. Is there any other way to have get_rules works after save()? because re-access the database will reduce performance, whereas the object is actually there and ready to be used. And my objective is to simplify my controllers, so I put all post-processes of a model in itself. Really appreciate your advice Thank you
[eluser]WanWizard[/eluser]
That is a good one. I think you have the same issue if you save, but the validation fails. If you have rules that transform values (such as serialize), it will leave the object in a transformed state. Get rules are run by the protected method _run_get_rules(), which is called after a row read has been converted to an object. I can't test it at the moment, but if you modify the save() method, and insert Code: $this->_run_get_rules(); Code: return ( ! empty($result) && ! in_array(FALSE, $result)); Let me know to I can push the fix to bitbucket.
[eluser]rick20[/eluser]
Hi Wanwizard, I already add this line: Code: $this->_run_get_rules(); Then I try it like this: Code: public function index() At first try, it works, but then after reloading the page I got this error: Quote:A PHP Error was encountered Do you know why? Thanks in advance
[eluser]WanWizard[/eluser]
Hmm... Just tried your test code here on the latest DM library (without modifying save), and the get rules work fine here. No matter what I do, the print_r() after save shows the array, not the string... edit: Take that back. It seems to be more complicated than this, sometimes it works, sometimes it don't. During testing I saw that notice pop up once. Also, if the column is empty, unserialize returns false instead of empty array, which isn't good either.
[eluser]WanWizard[/eluser]
Just pushed an updated version to bitbucket, could you try it?
[eluser]rick20[/eluser]
Hi Wanwizard, I just try it, but the problem seems still exist somehow, success on first time, and then error on second try. I notice that $this->_run_get_rules(); is actually executed, but then according to the warning line 5997, the particular field is already array, which is weird I think, why now it contains array instead of serialized array.
[eluser]WanWizard[/eluser]
Odd, I can not reproduce it, no matter how many times I reload the page with the test code. |
Welcome Guest, Not a member yet? Register Sign In |