Search code examples
phpnaming-conventionsredbean

Property Naming Convention


Paging Gabor de Mooij or anybody else who have been more experienced with RedBeanPHP. The current naming convention we have is using underscores and although anybody can make a case of using Pascal/Camel casing I think what's important is consistency and we don't want to refactor everything to just to conform to a consistent naming pattern but we'll see what we can do.

There's just these statements that are contradicting. Can anybody clarify this rule?

enter image description here

Also, don't you think 2 or more worded properties are also common and its ugly if they are all in lowercase: date_added or dateAdded?


Solution

  • RedBeanPHP has been designed for an 'agile' approach. The database gets crafted by RedBeanPHP on-the-fly, while you are coding the app and discussing the domain with your customer.

    However I will never impose artificial limitations. You can use underscores and uppercase characters, just remember that RedBeanPHP uses some conventions to retrieve/store relations: table_id and table1_table2 are the most important ones.

    Also note that uppercase table names can be very hard to maintain because some database-OS combinations are case-insensitive.

    As of RedBeanPHP 3.4 (now alpha) RedBeanPHP will throw an exception if you try to store a bean with an invalid type name; however this is just to warn you. To override this check use setStricTyping(false).

    Example:

    R::setStrictTyping(false);
    $bean = R::dispense('postAddress');
    $bean->housenumber = '1';
    R::store($bean);
    $bean = R::dispense('post_address');
    $bean->house_number = '2';
    R::store($bean);
    

    This will just work.

    I hope this clarifies the situation, I will update the docs to be more specific as soon as I have some time. Thank you for notifying me about this issue. Feel free to ask any question on our forum: https://groups.google.com/forum/?fromgroups#!forum/redbeanorm

    Note that your first message needs to be approved on the forum; however there was no other way to keep the spam away..