Closed benzon closed 4 years ago
You can use withCondition to filter lists:
$bean->withCondition(' age = ? ', [30])->ownInfo;
More details: https://redbeanphp.com/index.php?p=/using_sql_snippets
If you need to use criteria from multiple tables, a simple R::find() might be better though.
But how would it work with find ? how would i be able to do the conditions there just wondering?
Just thinking in the perspective of a search enigne function, since find might be the better solution.
$user = R::dispense('users');
$user->name = 'BenZoN';
$user->birthdate = '1983-08-25';
$status = R::dispense('status');
$status->whitelist = 0;
$status->ems = 0;
$status->police = 0;
$status->ped = 0;
$status->gang = 0;
$arr = array(
'charName' => 'Søren Benzon Eskildsen',
'age' => 31,
'description' => 'Blah Blah',
'experience' => 'Blah Blah',
'experience_ref' => 'DPL og DRP',
'freetext' => '',
'explain' => '',
'rules' => '',
'reaction_one' => '',
'reaction_two' => '',
'date' => date("Y-m-d H:i:s"),
);
$applicationJson = json_encode($arr);
$application1 = R::dispense('application');
$application1->type = 'whitelist';
$application1->status = 'wait';
$application1->application = $applicationJson;
$user->ownStatusList[] = $status;
$user->ownApplication[] = $application1;
$id = R::store($user);
This is my layout, what im trying to do is only get ex users where whitelist = 1 from status, not shure how to do this tho, and if its even possible.
Found a way to load all data base entrys before including all the own's now i can remember what that was damit :D
Hey there,
Each status is only linked to 1 user and each user only has 1 status? If so that's a one-to-one relation and status should be included in the user table, according to RedBean philosophy.
You can still get all users you are looking for this way:
$whitelisted_users = R::find( 'user', ' JOIN `status` WHERE `user`.id = `status`.user_id AND `status`.whitelist = ? ', [ 1 ] );
Hi might not be the right place.
But trying to understand RedBeanPHP, one thing i can't figure out tho, if i use the ownLists.
Is there anyway with find to only get ownEntrys with a specific value, ex, let's say i did a layout like this
Username Birthdate ownInfo - > ownInfo.age - > ownInfo.location
And i only want to get beans where the age is let's say 30, is there any way to do this with redbean, or do i have to get a list from the ownInfo table and then use ex the user_id to get the rest of the data?