jonathangeiger / kohana-jelly

See the link below for the most up-to-date code
https://github.com/creatoro/jelly
MIT License
146 stars 34 forks source link

Loading a newly created object #177

Closed chiurlo closed 13 years ago

chiurlo commented 13 years ago

Hello!

Thanks for a really helpful module. Apologies if the answer to this question is really obvious, but how can I access/load an object I've just created? For example:

$thing = Jelly::factory('thing') ->set(array('name' => $name, 'description' => $description, ))->save();

$thing_id = $thing->id();

This results in an error:

ErrorException [ Notice ]: Trying to get property of non-object

The object is successfully saved to the database, and I can access it later, just not within the current function. Where am I going wrong?

Thanks, Alison

banks commented 13 years ago

I think the issue here might be that save() has recently changed to allow it's return value to be checked for errors. (Although I could be wrong since I'm not fully up to date with latest changes and you haven't said which branch you are using).

If that is the case, then it just means you can't call save() in a chain like that. Does this work:

$thing = Jelly::factory('thing')->set(array(...));
$thing->save();
echo $thing->id();
chiurlo commented 13 years ago

Thanks so much -- that did the trick!