Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spelling of property key gets changed #12

Open
gossi opened this issue Aug 18, 2013 · 5 comments
Open

spelling of property key gets changed #12

gossi opened this issue Aug 18, 2013 · 5 comments

Comments

@gossi
Copy link

gossi commented Aug 18, 2013

I stored a property this way:

$obj->setProperty('key', 'value');

However, when I fetched them all with $obj->getExtraProperties() the key turned into KEY which is problematic, because the code follows with a case-sensitive spelling check and this breaks it completely.

@K-Phoen
Copy link
Member

K-Phoen commented Aug 18, 2013

You can disable this behavior by setting the normalize parameter to false in your schema.xml.
Example:

<table name="product">
  <column name="id" type="INTEGER" primaryKey="true" autoincrement="true" />
  <column name="name" type="VARCHAR" size="255" />
  <behavior name="extra_properties">
    <parameter name="normalize" value="false" />
  </behavior>
</table>

@gossi
Copy link
Author

gossi commented Aug 19, 2013

Thank you, I didn't know. Hard to guess from the docs, what normalize means in that context. Shouldn't there be no normalization at a default level?

@K-Phoen
Copy link
Member

K-Phoen commented Aug 19, 2013

I agree with you, it's one of the "gotchas" of this behavior. But on the other hand, it allows to directly call the getMyProperty() method for a my_property property. Without this normalization, we would have to name the property MyProperty to make it work.

That's why I'm in favour of adding a note about normalization in the readme, but I'm against disabling it by default.

@gossi
Copy link
Author

gossi commented Aug 19, 2013

I never tried, but from your explanation this code should work:

$obj->setProperty('my_prop', 5);
$obj->getMyProp();

without registering the property upfront? Anyway if not, the registerProperty method should trigger the normalization. My idea may sound foolish, I don't even know your code ;) From what I know that makes.

@K-Phoen
Copy link
Member

K-Phoen commented Aug 20, 2013

"Magic calls" like getMyProp() only work on registered properties, so no, this example does not work.
But yes, the registerProperty method triggers the normalization :)

At the moment, I can't see why we restrict to registered properties only, I'll investigate that in the future.

Generally speaking, I think that this behavior's code needs to be cleaned and harmonized a bit. We should identify points like this one and fix them during the cleaning phase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants