Ticket #6508 (closed defect: invalid)

Opened 8 months ago

Last modified 5 weeks ago

Why does _itemsByIdentity loop thru _arrayOfAllItems?

Reported by: guest Owned by: jaredj
Priority: normal Milestone:
Component: Data Version: 1.1.0
Severity: normal Keywords:
Cc:

Description

I posted to the mailing list 2/20, but I still think this looks like a problem. in ItemFileReadStore? line 493, it loops thru _arrayOfAllItems and I think it should be _arrayOfTopLevelItems. Why should it look for identifier in embedded objects. Is it logical to think that embedded objects would also have the same identifier?

Al Byers byersa@…

Attachments

programaticGridNestedAttr.htm (4.1 kB) - added by yaz_k83 6 weeks ago.
Demo to reproduce issue.

Change History

  Changed 8 months ago by bill

  • owner changed from anonymous to jaredj
  • component changed from General to Data

I don't see any reason to exclude items, but passing to Jared so he can answer directly.

  Changed 8 months ago by bill

PS: meant to say "exclude *nested* items"

  Changed 8 months ago by jaredj

  • status changed from new to closed
  • resolution set to invalid

Every item has a unique identifier, not just top level items. When you request by identifier, you are asking to locate a very specific item. It may be nested, or it may not, and therefore it searches all items, not just root level ones.

Changed 6 weeks ago by yaz_k83

Demo to reproduce issue.

  Changed 6 weeks ago by yaz_k83

  • status changed from closed to reopened
  • resolution deleted

Hi Jared,

I have come across a similar (perhaps the same) issue as raised by a guest above...

The issue is as follows: 1. When I have a nested object I am unable to use identifier. 2. If I use identifier field it expects the same to be used for the nested objects as well.

Now if I have details of students... with details like roll, name, marks, joiningDate (nested object with day, month, and year), etc; and roll no is the identifier, even nested fields like joining date need to have roll no. else the grid does NOT render itself.

I am attaching an HTML test file along, please try out the following... 1. run it as is... it should work. 2. Uncomment line no. 53 [identifier: 'roll',]; Now the code wont work... check fire bug for error message. you will see - [TypeError: arrayOfValues has no properties message=arrayOfValues has no properties]. 3 now uncomment the commented section of the joiningDate nested object from line no. 57 to 63 [roll: 10, ] - Now the code works..

This is a defect since identifier should be applicable only to the topmost level object and NOT to all the nested objects. Thank you.

Regards, Yazad Khambata

in reply to: ↑ description   Changed 6 weeks ago by yaz_k83

Kindly add me to the cc list for this ticket: yazad3@…

  Changed 6 weeks ago by jaredj

  • status changed from reopened to closed
  • resolution set to fixed

The store behaves as expected and as defined by its documentation. Every data item *must* have a unique identifier. Regardless of how it is nested. The fetchByIdentity() API makes no distinction between a nested item and a top level item in the data tree.

I repeat, this is not a bug in the store. If you have nested items, they too must have unique identifiers to they can be looked up directly, same as a top-level item.

  Changed 6 weeks ago by jaredj

If you want to treat complex values as non-items with ItemFile?*Store (IE, they are not Items from the perspective of ItemFile?*Store) and are not bound by the identity requirement, then you can do that through the custom type map capability of ItemFile?*Store.

CustomType? maps are a way to tell ItemFile?*Store that a value of a particular attribute is in itself not a unique data store item, but just a value, same as a string, int, boolean, etc.

See: http://docs.dojocampus.org/quickstart/data/usingdatastores/faq#question-9-in-one-of-my-items-in-itemfilereadstore-i-defined-an-attribute-value-as-a-javascript-object-when-i-access-it-through-store-getvalue-it-has-been-modified-why

See: http://docs.dojocampus.org/dojo/data/ItemFileWriteStore#custom-type-examples

If you still want those nested fields to be treated as items and they can't have roll no, then roll no can't be used as the 'identifier'. You could, in fact, not assign any attribute as an identifier (leave off the identifier field from your dataset), and ItemFile?*Store will assign its own identifiers to your data that are not based off public fields (Effectively just the index count of the array of items). That way you're also guaranteed not to collide.

Which is, incidentally, why commenting out identifier works for you in this case. The store auto-assigned some for you.

Those are the options you have for ItemFile?*Store:

1.) Apply identifier attribute that is unique to ALL JavaScript? objects in the data you are passing as data store items.

OR:

2.) Don't assign an attribute the role of identifier and let the store auto-assign unique ones.

OR:

3.) Use a custom type map to make the ItemFile?*Store treat the joining field value as a straight value and not a data store item.

  Changed 5 weeks ago by jaredj

  • status changed from closed to reopened
  • resolution deleted
Note: See TracTickets for help on using tickets.