Get Bean with his relations like other Bean

41 views
Skip to first unread message

miblint

unread,
May 4, 2012, 8:50:00 AM5/4/12
to redbeanphp
hi again!
I'm storing a product Bean, by this way:

$product = R::dispense( 'product' );
$product->name = $_POST['nombre'];
$product->description = $_POST['description'];
$product->price = $_POST['price'];
$product->category = $_POST['category'];
R::store( $product );

How can I indicate that the category's attribute is a reference (or
FK) to the category Bean? I try with:

$products = R::find( 'product' );
foreach( $products as $product )
print_r( $product->ownCategory ); //print empty array


is there any awy to indicate relations with Foreing Keys or something
like this?

Thanks!

Rodrigo Gregorio

unread,
May 4, 2012, 11:42:16 AM5/4/12
to redbe...@googlegroups.com
try

$product = R::dispense( 'product' ); 
$product->category_id = $_POST['category_id']; 
R::store( $product );

$category = R::load( 'category',$id ); 
print_r($category->ownProduct);

miblint

unread,
May 4, 2012, 5:48:05 PM5/4/12
to redbe...@googlegroups.com
I solved this by this way:


I think is a brilliant ORM library, but in humble opinion, the library need some examples or tutorials about this topic.
If you see the questions that the users make, this topic is one of the most important.

Thanks again, and congrats for this work!

I hope you undestand my English!! 
Bye!

Rodrigo Gregorio

unread,
May 5, 2012, 12:26:37 PM5/5/12
to redbe...@googlegroups.com
ok, this works

but objects to the relationship with foreign keys is "category_id" no "category" and the primary key is "id"

thanks for share your solutions

gregorinator

unread,
May 14, 2012, 4:41:59 PM5/14/12
to redbe...@googlegroups.com
On 5/4/12, miblint <mauri...@gmail.com> wrote:
> I think is a brilliant ORM library, but in humble opinion, the library need
> some examples or tutorials about this topic.

Sorry for dropping in on this thread so late -- I've been travelling
-- but if you haven't seen it yet, you might find this tutorial
useful:

http://www.redbeanphp.com/manual/docs/connectingbeans01.pdf

gs
Reply all
Reply to author
Forward
0 new messages