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

DataModel で base を指定すると base に指定した Model の作成に失敗するようになる #198

Closed
3bch opened this issue Apr 29, 2013 · 1 comment
Assignees
Labels
Milestone

Comments

@3bch
Copy link

3bch commented Apr 29, 2013

確認した環境

  • OS: OSX 10.8.3
  • ブラウザ: Google Chrome 26.0.1410.65, Firefox 19.0.2 (他のブラウザは試してません)
  • hifive: 1.1.4-all に含まれる dev 版

問題発生の状況

以下のようなコードを書いたとき parentModel を create するタイミングでエラーが発生します。

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>hifive DataModel BUG</title>
    </head>
    <body>
        <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
        <script src="/hifive/h5-1.1.4.dev.js"></script>
        <script>
            var manager = h5.core.data.createManager('DataManager', 'model');

            var parentModel = manager.createModel({
                name: 'ParentModel',
                schema: {
                    id: {
                        id: true,
                        type: 'integer',
                    }
                }
            });

            var childModel = manager.createModel({
                name: 'ChildModel',
                base: '@ParentModel',
                schema: {
                    name: {
                        type: 'string',
                    }
                }
            });

            parentModel.create({ id: 0 });
        </script>
    </body>
</html>

Chrome だと h5-1.1.4.dev.js の 10710行目 で Uncaught TypeError: Object #<Object> has no method 'name' が発生し、Firefox だと同じ箇所で TypeError: this._itemValueCheckFuncs[prop] is not a function が発生することを確認しました。

childModel 側を削除するとエラーが発生しなくなることから、base を継承した側の name が base 側に影響をおよぼしてしまっているようです。

原因と思われる箇所

ちょっと原因を追ってみたんですが、base を指定した Model を createModel() で設定しているあいだに、validateDescripter() の中(h5-1.1.4.dev.js の 9500行目)で以下のように baseSchema を書き換えている部分が原因ではないかと思います。

schema = $.extend(baseSchema, schema);
fukudayasuo pushed a commit to hifive-labs/hifivemain that referenced this issue May 7, 2013
@ghost ghost assigned fukudayasuo May 7, 2013
@simdy simdy closed this as completed May 7, 2013
@simdy simdy reopened this May 7, 2013
fukudayasuo pushed a commit to hifive-labs/hifivemain that referenced this issue May 7, 2013
@fukudayasuo
Copy link

schema = $.extend({}, baseSchema, schema);

として、baseSchemaを上書かないようにして修正しました。
また、baseSchemaが上書かれることでたまたま動いていた箇所があったので、その他の箇所も修正しました。

fukudayasuo pushed a commit to hifive-labs/hifivemain that referenced this issue May 7, 2013
simdy pushed a commit to hifive-labs/hifivemain that referenced this issue May 10, 2013
fukudayasuo pushed a commit to hifive-labs/hifivemain that referenced this issue May 10, 2013
@simdy simdy closed this as completed May 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants