gabordemooij / redbean

ORM layer that creates models, config and database on the fly
https://www.redbeanphp.com
2.31k stars 279 forks source link

In OODBBean::__set(), the suffix value you use to create $fieldLink causes problems. #476

Closed YellowSharkMT closed 8 years ago

YellowSharkMT commented 9 years ago

This code is problematic for tables that happen to have columns named something, and something_id, from OODBBean.php, line 1003:

public function __set( $property, $value )
{
    // skip to line 1030:       
    $fieldLink      = $property . '_id';
    // skip to line 1056:
    if ( array_key_exists( $fieldLink, $this->properties ) && !( $value instanceof OODBBean ) ) {
         // this block either ends or fails the __set() method

Would it be possible to chance that '_id' suffix to something with a lower chance of causing this sort of conflict? There appears to be no reason you couldn't change it to some value that'd be less likely to conflict with a legitimate column name, like "_id_for_fieldLink", or anything really.

Glad to submit a pull request if that'd be helpful; I figured I'd bring it up first though, in case there's reasoning behind this that I am not aware of. OK, thanks!

gabordemooij commented 9 years ago

So you have a column 'something_id' that does not point to 'something' ? RedBeanPHP has been designed to work like this. It uses 'predictable' columns for a reason, to make the mapping easy, yes that means it might be incompatible with some existing schemas, that's a tradeoff. However, to gain a better understanding of the situation, can you elaborate on why you have a foreign key pointing to ... well, to what? What does something_id refer to in your case?