phpredbean

RedBeanPHP how to wrap bean over already existing table?


I am tying to create API with RedBeanPHP and I have following case: Have to find all records from table with name "my_data01"

R::findAll( 'my_data01' );

But my model class have name 'Product.php' which contains of

class Product  extends SimpleModel
{
public $attributes = array();

public function dispense() {}

...//other methods
}

I want to somehow wrap my table "my_data01" inside bean (may be) that has name Product. and when using code like:

R::findAll( 'product' );

It will query "my_data01" table. How can i do that? thnx


also a have used define( 'REDBEAN_MODEL_PREFIX', 'myapp\\' ) for corecctly loadyng model for current bean


Solution

  • You can't do that in RedBean. The ORM is intrinsically linked to its own data structure. I'd suggest importing my_data01 into a new table called product. Indeed, the manual for RedBean states:

    You should also NOT use RedBeanPHP if you don't like the RedBeanPHP schema policies and you want complete control over the layout of your database schema, i.e. the column names used for primary keys and foreign keys.

    Your other alternative of course, is to use another ORM which offers more flexibility, for example Doctrine or Eloquent.