Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6613901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:16:24+00:00 2026-05-25T20:16:24+00:00

Already used as many ORMs as you can imagine. At moment I’m in a

  • 0

Already used as many ORMs as you can imagine. At moment I’m in a love / hate crush with RedBean PHP. Here we go… after a few hours studying it I got a doubt about whats the better way to solve this very basic problem (best way means, in this case, the way that better fits to the RedBean’s ease of use philosophy):

It’s very common to limit access to some properties of our classes so we can prevent certain kinds of wrong data manipulation. This is usually accomplished with good use of getters and setters. But as far as already know about RedBean, there are no formal setters in the native classes, only some public properties that can be changed and persisted in the database.

What I would like to do is to protect some properties from being changed manually, so I can avoid other programmer to make any kind of weirdness like:

$beam->insertion_date = 'yesterday';
R::store($beam);

That field should never be changed after the row insertion, obviously, but we can’t just trust no one will do that. Is there a way to achieve something like turning the insertion_date a protected property or making it inaccessible in some way?

I have a feeling that the best way to do that is using $beam->setMetadata() and declare that a given property shouldn’t be changed, but I don’t know how to achieve this in RedBean and still couldn’t find enough information in the official manual. Any help is appreciated.

Thanks for reading.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:16:25+00:00Added an answer on May 25, 2026 at 8:16 pm

    Found a solution!

    1. On your model, store the state of a bean on a private property every time a bean is loaded from the database.
    2. Before put things back in the database, test if the values that shouldn’t have been changed were changed programatically.

      • In positive case, Throw an exception or add any other event to
        warn the programmers that they are trying to change probably by
        mistake
        a field that shouldn’t be changed.

    This is how the example model should look now:

    class Model_book extends RedBean_SimpleModel{
    
        protected $before = false;
    
        public function open(){
            if($this->bean->id){
                $this->before = clone($this->bean);
            }
        }
    
        public function update(){
            if($this->bean->id){
                if($this->before->insertion_date != $this->bean->insertion_date){
                    throw new exception ("The insertion_date can't be changed.");
                }
            }
        }
    }
    

    So now the following code would result in exception:

    $beam->insertion_date = 'yesterday';
    R::store($beam);
    

    Note: the use of RedBean’s meta information API would be a better
    solution, but it wouldn’t make sense to add (only) this validation
    criteria without add a complete validation layer on top of RedBean. On
    the other hand, add a custom full validation would become useless in
    case a built-in validation get added to the ORM in the near future (I
    bet it will happen), so I’ll leave it as it is for now.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Already overloaded operators <<,>>,= etc are used many times. An example that i was
i already used many dialogbox in my app. but now, i dont want to
this is my first question, although I've already used so many tips from Stack
How many of you already used the Prana Framework for AS3 (Flex/Flash) or heard
ORA-00955: name is already used by an existing object There are so many statements
May be some body already used some open source component, writing on jquery. And
sending mail along with embedded image using asp.net I have already used following but
I used to configure boost already, but this time I have no idea what
So as many of you may already know, CommonCrypto isn't included in the iPhone
I have already searched for many questions at Stackoverflow, but I really didn't consider

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.