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

Cannot save entyity that refereces many other entities #61

Open
siemionides opened this issue Nov 3, 2014 · 0 comments
Open

Cannot save entyity that refereces many other entities #61

siemionides opened this issue Nov 3, 2014 · 0 comments

Comments

@siemionides
Copy link
Contributor

Hello,

I have following models:

    class Badge
      include Diametric::Entity
      include Diametric::Persistence::Peer

      attribute :category, Ref
      attribute :date, DateTime
      attribute :description, String
      attribute :enum_value, String
      attribute :enumeration, String, :cardinality => :many
      attribute :id, UUID
      attribute :name, String
      attribute :type, Ref
      attribute :value, Double
      attribute :week, Integer
      attribute :year, Integer
    end

and

class Person
  include Diametric::Entity
  include Diametric::Persistence::Peer

  attribute :name, String
  attribute :id, UUID, :unique => :identity
  attribute :badges, Ref, :cardinality => :many
  attribute :address, String
  attribute :city, String
  attribute :state, String
  attribute :country, String
  attribute :zip_code, String
  attribute :phone, String
  attribute :email, String
  attribute :age, Integer
  attribute :gender, Ref
end

My intention is to create Person with two Badges.

badge = Badge.new(name: "average_weekly_revenue", value: 30.0, date: DateTime.strptime('2014-10-21T04:05:06', '%Y-%m-%dT%H:%M:%S'))
badge.save

badge2 = Badge.new(name: "some_other_badge", value: 20.0, date: DateTime.strptime('2014-10-21T04:05:06', '%Y-%m-%dT%H:%M:%S'))
badge2.save

so when I create new person:

user_id = UUID.generate
person = Person.new(name: "Natalia Jolie", id: user_id, badges: [badge, badge2])
person.save

I'm being given:

RuntimeError: java.lang.IllegalArgumentException: :db.error/not-an-attribute 17592186045435 is not an attribute.
 get at diametric/DiametricListenableFuture.java:44
save at /Users/michalsiemionczyk/.rvm/gems/jruby-1.7.15/gems/diametric-0.1.3-java/lib/diametric/persistence/peer.rb:15
testD at /Users/michalsiemionczyk/Projects/yeti-backend/michals-test/test.rb:115

And that points to the

 person = Person.new(name: "Natalia Jolie", id: user_id, badges: [badge, badge2])

line. The 17592186045435 number is a dbid of the first badge.

I've tried another approach described in the tutorial in here https://github.com/relevance/diametric#association

user_id = UUID.generate
Person.new(name: "Brad Dipp", id: user_id).save
person = Diametric::Query.new(Person, @conn, true).where(name: "Brad Dipp").first
person.update_attributes(badges: [badge, badge2])
person = Diametric::Query.new(Person, @conn, true).where(name: "Brad Dipp").first

puts person.badges.collect(&:name)

and that throws the same error that points to the person.update_attributes(badges: [badge, badge2]) line.

When I tried the tutorial it throws the same error on me.update_attributes(kids: [mario, luigi]) .

Naturally I'm fine when adding associations with :cardinality => :many, but for my schema I need multiple references.

How to make it work?

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

1 participant