Ashikawa for data modeling

34 views
Skip to first unread message

Patrick Mulder

unread,
Nov 16, 2012, 5:59:08 PM11/16/12
to ashi...@googlegroups.com
Hi Lucas,

very interesting talk of you today on your projects.

I was just playing around with Ashikawa::AR and it works fine:
I made an Article class and can save and read instances nicely, as well as see them in the arangosh shell.

However, for my use case, I didn't see any example of how to have Array attributes, such that I could write:

 article.tags << Tag.new(name: 'awesome')

also, I would like to attach tags to another class, e.g.

  authors.tags << Tag.new(name: 'funny')
  authors.tags << Tag.new(name: 'awesome')


Also, what would be my options to see all children of a given tag?


Well, it would be great to understand a bit more on the code options!

Thanks!
Patrick


PS  I wanted to ask in the talk about cursors too... any common patterns that you use / found helpful for searching data?



Lucas Dohmen

unread,
Nov 17, 2012, 5:09:55 AM11/17/12
to ashi...@googlegroups.com
Hi Patrick,

I created an example for you:
https://gist.github.com/4094497

The documentation of AR needs some improvement :) Thanks for pointing out this aspect to me,
I will work on that :)

I hope this answers your questions from the main part of your mail? :)

Could you concretise your question from the PS? :)

Best Wishes,
Lucas

Patrick Mulder

unread,
Nov 17, 2012, 3:15:37 PM11/17/12
to ashi...@googlegroups.com
Hi Lucas,

nice!

arangosh> db.users.byExample({name: 'patrick'}).toArray()
[
  { 
    _id : "2916696487/3629334951", 
    _rev : 3629334951, 
    name : "patrick", 
    tags : [
      "nosql"
    ]
   }
]

 And

[
  { 
    _id : "3627237799/3629990311", 
    _rev : 3630121383, 
    title : "Awesome article", 
    author : "patrick", 
    tags : [
      "nosql"
    ]
   }
]

Ok, what about embedding article in user, or querying all documents that are tagged with 'nosql' ? Especially, for scalability issues, when I would use a tags collections, how would you advise to store user and article documents into the tag collection? How might an m-n association like here: http://stackoverflow.com/questions/4121632/mongoid-many-to-many-problem look like in Arango?

Thanks,


Patrick

Patrick Mulder

unread,
Nov 30, 2012, 6:26:25 AM11/30/12
to ashi...@googlegroups.com
Hi Lucas,

great, I played a bit more with Ashikawa, and some observations/questions:


a) A 'person' document is inserted automatically in the 'people' collection? This is default Rails pluralization, I guess?

b) I defined the following association between Person and Tag:
  
class Person
    ...
   attribute :tags, Array[Tag] 
end

Hmm.. but now I am bit confused by the concept of referencing vs. embedding an object, as in the Arangosh console I see this:

arangosh> db.people.all().toArray();
[{ _id : "9781671/10895783", _rev : 13255079, name : "Patrick", tags : [{ name : "programmer" }] }]

while I also see a 'tags' collection with content:

arangosh> db.tags.all().toArray();
[{ _id : "11288999/12927399", _rev : 12927399, name : "CSS" }, { _id : "11288999/12403111", _rev : 12403111, name : "CSS" }]

Thanks for sharing your ideas/teaching me a bit, how to look at this data model!

BR,
Patrick

Lucas Dohmen

unread,
Dec 3, 2012, 4:58:17 AM12/3/12
to ashi...@googlegroups.com
Hi Patrick,

a) This is correct :) It uses the pluralization of ActiveSupport, because I think it makes a lot of sense :)

b) Sorry for the confusing behavior. This is currently really confusing. The reason for that is that I haven't finished this particular part of Ashikawa::ActiveRecord.
Why?
Because I'm not sure if embedding should be the default behavior. What do you think? Would you expect embedding or referencing in your example?

@Tobi, please feel free to chime in :)

Best Wishes,
Lucas

Patrick Mulder

unread,
Dec 3, 2012, 5:15:21 AM12/3/12
to ashi...@googlegroups.com
On Mon, Dec 3, 2012 at 10:58 AM, Lucas Dohmen <lucas....@rwth-aachen.de> wrote:
The reason for that is that I haven't finished this particular part of Ashikawa::ActiveRecord.
Why?
Because I'm not sure if embedding should be the default behavior. What do you think? Would you expect embedding or referencing in your example?


Hmm.. not sure, from my experiments so far with Mongoid. I ran a bit into problems sometimes when trying to assign embedded documents, as well as filter/load embedded documents. I ended up quite a few times by manually defining my associations 'manually' in methods.. but not sure if it's my current understanding, or the Gem's source of confusion...

So what I do sometimes is adding a method for denormalizing a document as shown in this method:


I think I've read something by John Nunemaker, that a detailed driver as ActiveRecord is not necessary with document oriented DBs, but I am not finding that comment right now...

 

Patrick Mulder

unread,
Dec 3, 2012, 6:35:07 AM12/3/12
to ashi...@googlegroups.com
On Mon, Dec 3, 2012 at 11:15 AM, Patrick Mulder <mulder....@gmail.com> wrote:
On Mon, Dec 3, 2012 at 10:58 AM, Lucas Dohmen <lucas....@rwth-aachen.de> wrote:
The reason for that is that I haven't finished this particular part of Ashikawa::ActiveRecord.
Why?
Because I'm not sure if embedding should be the default behavior. What do you think? Would you expect embedding or referencing in your example?


Hmm.. not sure, from my experiments so far with Mongoid. I ran a bit into problems sometimes when trying to assign embedded documents, as well as filter/load embedded documents. I ended up quite a few times by manually defining my associations 'manually' in methods.. 

Hi Lucas,

hm... has_many could take a property may be:

class User
  has_many :tags, embedded: true  # (or denormalized: true )
end


class Tag
   belongs_to :user
end


Apart from this, I was thinking that graph based associations might be quite interesting, like:

class User
  has_skills_by :tags
  lives_in :location
end

class Tag
  is_skill_of :user
end

Now, you could match Users according to Location and Tags, like:

User.skills_by_tags("html").lives_in("Boston")
=> [ ... ]

this is just thinking out loud however.... maybe not possible to develop so easily.



 

Lucas

unread,
Dec 5, 2012, 10:51:52 AM12/5/12
to ashi...@googlegroups.com
Hi Patrick,

Thank you for your input :)

I think it is a good idea to provide the information if it is embedded or not via an option as you suggested.
I would go with embedded, because I think it is easier to understand than denormalized.
Let me investigate that! I created a ticket for this discussion: https://github.com/triAGENS/ashikawa-ar/issues/12

About the graph based associations:
I'm very interested in all ideas about modeling the graph on the Ruby side. There is absolutely no good solution yet for any of the graph databases, and I want to create one :) The graph functionality will be enhanced massively in the near future (by some other folks and me), and I want to provide the tools on the Ruby side.
But I don't get entirely how your proposed solution works! User and Tag are both Vertices? What are the edges?

Best Wishes,
Lucas

Patrick Mulder

unread,
Dec 5, 2012, 11:07:42 AM12/5/12
to ashi...@googlegroups.com
On Wed, Dec 5, 2012 at 4:51 PM, Lucas <lucas....@koeln.de> wrote:
I'm very interested in all ideas about modeling the graph on the Ruby side. There is absolutely no good solution yet for any of the graph databases, and I want to create one :) The graph functionality will be enhanced massively in the near future (by some other folks and me), and I want to provide the tools on the Ruby side.
But I don't get entirely how your proposed solution works! User and Tag are both Vertices? What are the edges?

ok, great! I think I'll reply in a own thread, makes discussions maybe easier, if someone just wants to talk about the graph part ;-) 
The embedded solution sounds great too, by the way. I am hoping to get going with a more conrete Rails app based on Ashikawa in few weeks. I am just automating my server with Chef, and from there on, I'll prepare for different experiments with the DB layer. 

Lucas Dohmen

unread,
Dec 6, 2012, 4:41:15 AM12/6/12
to ashi...@googlegroups.com
Nice :) So I'll talk about the two parts at their new places ;)
Just a quick note: If you have a Chef recipe for setting up ArangoDB, please share it with us :)
Reply all
Reply to author
Forward
0 new messages