Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Use Model_CRUD or ORM, but write your own sql?
  • Hi folks Obviously for the simple stuff, its great to have shortcuts. But one handy thing about CI/Datamapper ORM is, when database queries get complex, you can always use the query() method to write your own sql query (with bindings), and it would populate your model. Does such a method exist in either Model_Crud or Orm? I haven't found it so far. I like the shortcuts, find() etc., but I dont want to have to use them if I base my model on either Model_Crud or Orm\Model. Colm
  • In FuelPHP both Model_Crud and Orm\Model are layers on top of the query builder, but they are not an extension of that query builder, so you can't do what you can do in Datamapper. Instead, you run a normal query builder query, and ask it to return the results as model objects:
    $result = DB::select()->from('table')->as_object('Model_Mymodel')->execute();
    

    Which will return an array of Model_Mymodel objects. This definately works with ORM models, I haven't used this technique with Model_Crud, but I'm pretty sure it works there too.
  • Hi Harro Bingo. Works like a charm with Model_Crud too. Thanks! Colm

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion