Git Product home page Git Product logo

Comments (4)

hzamani avatar hzamani commented on June 26, 2024

A game is a node an belongs to another node? Even if this is the case,
polymorphic makes no sense. We usually don't use a model name as a
polymorphic relation name.

This was what I got on the first look. I am going on a trip with no
internet access, so next reply will be on next week!
On Mar 14, 2013 3:42 AM, "derrelldurrett" [email protected] wrote:

I have the following relationships via acts_as_relation:

class Node < ActiveRecord::Base
acts_as_superclass
belongs_to :game, polymorphic: true
#...end
class Game < ActiveRecord::Base
acts_as :node
has_many :ancestors, class_name: 'Node',
foreign_key: 'ancestor_id'
#...end
class Team < ActiveRecord::Base
acts_as :node

...end

When I add a to the list of in another , I get:

ActiveRecord::AssociationTypeMismatch: Node(#30169720) expected, got
Game(#24699180)
/home/rev/.rvm/gems/ruby-1.9.3-p385@global/gems/activerecord-3.2.12/lib/active_record/associations/association.rb:204:in
raise_on_type_mismatch'
/home/rev/.rvm/gems/ruby-1.9.3-p385@global
/gems/activerecord-3.2.12/lib/active_record/associations/collection_association.rb:494:inblock
in concat_records'
/home/rev/.rvm/gems/ruby-1.9.3-p385@global/gems/activerecord-3.2.12/lib/active_record/associations/collection_association.rb:493:in
each'
/home/rev/.rvm/gems/ruby-1.9.3-p385@global
/gems/activerecord-3.2.12/lib/active_record/associations/collection_association.rb:493:in
concat_records'
/home/rev/.rvm/gems/ruby-1.9.3-p385@global/gems/activerecord-3.2.12/lib/active_record/associations/collection_association.rb:132:in
concat'
/home/rev/.rvm/gems/ruby-1.9.3-p385@global
/gems/activerecord-3.2.12/lib/active_record/associations/collection_proxy.rb:116:in
<<'
/home/rev/RubymineProjects/AliasMadness/app/models/bracket_factory.rb:17:in
`block in create_bracket'

If I examine the Game object in the debugger, returns , which makes no
sense, given the above.

Do you have any suggestions for how I can proceed? This is rails 3.2.12
under ruby 1.9.3.


Reply to this email directly or view it on GitHubhttps://github.com//issues/26
.

from acts_as_relation.

derrelldurrett avatar derrelldurrett commented on June 26, 2024

Nodes 1

So, yes, Games belong to and are Nodes. Teams are also Nodes. Games 1) must have two "ancestors", which can be either a Game or a Team, 2) eventually have another Team (which relationship is not shown for purposes of clarity).

Part of your comment doesn't make much sense to me (which suggests I'm doing something wrong): "We don't usually use a model name as a polymorphic relation name." I went through several iterations of code attempting to get a working relationship, and what you see above was the version that managed to get through the compile step.

Previous attempts included this combination:

class Node < ActiveRecord::Base
  acts_as_superclass
  belongs_to :ancestor, polymorphic: true
  # ...
end

class Game < ActiveRecord::Base
  acts_as :node
  has_many :nodes, as: :ancestor
  # ...
end

Those would fail because ancestors wasn't a method on a Game object.

from acts_as_relation.

hzamani avatar hzamani commented on June 26, 2024

Maybe it's to late! But why polymorphic: true is there?

from acts_as_relation.

derrelldurrett avatar derrelldurrett commented on June 26, 2024

Not too late (I'm always looking to understand what I missed the first time through).

In the earlier attempt, I was trying to express the relationship that Nodes, being the superclass, were potentially either Games or Teams.

I've been away from this for some time. So, if I'm saying something incomprehensible, it may be a lack of memory or a genuine lack of understanding something. If you could be more verbose and explicit, that would be helpful.

from acts_as_relation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.