Need more RedBeanPHP tutorials

Asked by Total Lag

I am curious how models/FUSE will work with the built-in ORM? Is it as simple as include('redbeanmodel.php'); and firing off queries or is there more to it? I just want to correct use the intended built-in feature so additional tutorials on how to utilize this ORM would be helpful!

I was thinking something along the lines of:

<?php
    // Hello world heading.
    echo "<h1>Hello, world!</h1>";

    // Call ORM plugin.
   include('redbeanmodel.php');
    $this->factory('orm');

    // Do the query
    $books = R::find('example_book');
?>

In redbeanmodel.php:
class Model_example_book extends RedBean_SimpleModel {
        public function update() {
            if (count($this->ownBooks)>4) {
                throw new Exception('too many!');
            }
        }
    }

and how would you "freeze" RedBeanPHP in PHPDevShell?

Question information

Language:
English Edit question
Status:
Solved
For:
PHPDevShell Edit question
Assignee:
No assignee Edit question
Solved by:
TitanKing
Solved:
Last query:
Last reply:
Revision history for this message
TitanKing (titan-phpdevshell) said :
#1

Hi Total Lag,

There is an example in the Example plugin of how this works. It is very simple really.

Regards,
Jason

Revision history for this message
Total Lag (phanx068) said :
#2

It is simple. Perhaps too simple lol. I guess my thoughts were what would be the most easiest/efficient way to query? Should I make a phpdevshell model so I can use invokeQuery but instead of sql use rb in the model or should I just not use invokeQuery at all and use just only RB functions/models? If there aren't any implications using one over the other then I guess my question is moot :)

Revision history for this message
Best TitanKing (titan-phpdevshell) said :
#3

Once rb is a factory you don't have to use invokeQuery at all.
On 31 Jan 2013 6:46 PM, "Total Lag" <email address hidden>
wrote:

> Question #220625 on PHPDevShell changed:
> https://answers.launchpad.net/phpdevshell/+question/220625
>
> Status: Answered => Open
>
> Total Lag is still having a problem:
> It is simple. Perhaps too simple lol. I guess my thoughts were what
> would be the most easiest/efficient way to query? Should I make a
> phpdevshell model so I can use invokeQuery but instead of sql use rb in
> the model or should I just not use invokeQuery at all and use just only
> RB functions/models? If there aren't any implications using one over
> the other then I guess my question is moot :)
>
> --
> You received this question notification because you are an answer
> contact for PHPDevShell.
>

Revision history for this message
Total Lag (phanx068) said :
#4

Thanks TitanKing, that solved my question.

Revision history for this message
Greg (gregfr) said :
#5

RedBeans and PHPDS_query are two different philosophies.

RedBeans tries to abstract the data structures by adding a layer of "intelligence" which converts the abstracted data to/from the actual database. Also, as a separate product, it has its own community, and support several databases. It also adds features like listeners.

The PHPDS_query is a way to lighten the work of using SQL by adding what you don't write. It's slimer then redbeans, integrated into PHDS. It's faster and has less features.

You can work with one or the other depending on your project. You can even work with both, but not together.

greg

Revision history for this message
Total Lag (phanx068) said :
#6

Thank you Greg and TitanKing! "You can even work with both, but not together." really clears things up!