Comments (4)
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.
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.
Maybe it's to late! But why polymorphic: true
is there?
from acts_as_relation.
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)
- Extending Devise's User to Roles using acts_as_relation HOT 1
- Cannot instantiate an subclass HOT 3
- Rails 3.2 - .specific is not working? HOT 1
- PG::UndefinedColumn, ActiveRecord::StatementInvalid HOT 1
- Cannot use created_at or any timestamp columns to query: ambiguous column name HOT 2
- Nested form splitting child records across multiple rows HOT 2
- Circular reference issue when running migration HOT 3
- Association field name error (assuming default convension names) HOT 1
- Name of the has_one assiocation HOT 1
- Pen.where(name: "...") doesn't work HOT 1
- Rails 4 + ActiveAdmin compatibility (Migration error) HOT 12
- Dependent Destroy does not work ? HOT 1
- Including a "whole" object in json
- Make record duplication possible
- Saving the parent object doesnt save changes to the child HOT 1
- Move version.rb into acts_as_relation directory HOT 1
- Infinite loop unexistant method/`respond_to?` on `.specific` HOT 1
- PG::Error: ERROR: relation "users" does not exist
- SQL request problem
- Gem dependencies incorrect HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from acts_as_relation.