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

question regarding schema and object types #58

Open
logicminds opened this issue Sep 29, 2014 · 2 comments
Open

question regarding schema and object types #58

logicminds opened this issue Sep 29, 2014 · 2 comments

Comments

@logicminds
Copy link

I have a general question about creating a schema that has arrays and hashes in the model. If I understand some of this correctly I would need a has_many relationship for tags because this entity can have many tags. However, for my metadata how do I specify this as it will be a hash of key/value information. The remote Api will return JSON code with arrays and hashes so its unclear to me how to consume the data when the schema only supports primitive types.

Example:

entity "Item" do
    string :name, optional: false
    string :title, optional: false
    string :uuid, optional: false
    string :type, optional: false
    string :tags, optional: false (How do I make this an array)
    string :metadata optional: false (How do I make this a map/hash)

  end
@kemiller
Copy link
Contributor

CDQ does not offer any special support for hash or array. You can use a transformable type attribute and store a hash in there, and that's a common thing to do.

http://stackoverflow.com/questions/16593431/nsdictionary-and-core-data

Depending on the shape of your data, though, the best and most reliable may be to do another has many with both a key and value column, and look them up like item.metadata.where(:key).eq("mykey").

Good luck. Native support for these is something I'd like to add in the future.

@logicminds
Copy link
Author

Ah, so its a limitation of core data and serialization. Ok so the has_many makes sense but what if I don't have a 1-to-many relationship like in metadata. Is there a one-to-one relationship? @kemiller

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