Displaying 20 results from an estimated 300 matches similar to: "Polymorphic associations and single table inheritance"
2011 Apr 05
1
Why does AR use base_class for polymorphic relationship "type"
I have a couple models that inherit from a base class that then
inherits from AR.
When they are used in a polymorphic relationship the "type" is always
the base class.
Just curious if anyone has a reason why it doesn''t use the *actual*
class rather then the base_class. I have patched AR to use the actual
class if !base_class.table_exists? but it adds another query each time
2007 Nov 20
2
Plugin: create instance methods dynamically in ClassMethods?
Hi all
I have the following plugin code:
module IncenseCrud
def self.included(base_class)
base_class.extend(ClassMethods)
end
module ClassMethods
def performs_incense_crud
def index
list
return render(:action => ''list'')
end
end
end
end
In init.rb I have the following:
require File.dirname(__FILE__) +
2008 Sep 25
1
defining polymorphic type condition
As great as Rails 2.1 is, I for the life of me cannot figure out why
polymorphic associations do not support reconfiguring the type column
used.
For example, I have no way to do a polymorphic association using a
lookup hash which maps an integer to a class name.
Storing a TINYINT unsigned is waaaaay more efficient than storing a
string like "SomeActiveRecordModel" over and over again.
2006 Mar 20
3
help: acts_as_versioned setup error "undefined local variable or method ''base_class''"
Hi All,
Rails newbie here trying to set up acts_as_versioned according to Chapter 14
in the Rails Recipies book. I''ve taken the following steps (nearly
verbatim) as mentioned by the book:
- created the target model "Post"
- added the "acts_as_versioned" label to the model file
- generated a migration file
- added the table creation code and the command
2006 Jul 15
2
FieldQuery not returning anything
Hey ..
The QueryParser RDoc page explains to me on how to search for a specific
value in a specific field. This is not working the way i thought it
should be, what am i doing wrong? Here''s an example ..
I''m storing model data in the index like this:
doc << Field.new( "object_id", object.id, Field::Store::YES)
doc << Field.new( "type",
2008 Feb 22
2
marshaling ActiveRecord objects: how to unload associations?
I''m marshaling ActiveRecord objects, and I want them to be as small as
possible. How can I unload everything that can be reloaded from the
database?
If they''re marshaled before any of the associations are referenced
then the referenced objects aren''t dumped. But if the association has
been loaded, how can I unload it? AssociationProxy.reset doesn''t seem
to do
2011 Oct 06
1
[LLVMdev] TableGen For Loops
greened at obbligato.org (David A. Greene) writes:
> So here's why I think the for loop proposal can't be a preprocessing
> phase. Down in the guts of this I fundamentally need to be able to do
> this:
>
> multiclass blah<list<int> Values> {
> for v = Values {
> def DEF#v : base_class<v>;
> }
> }
>
> Will that work? Is the for
2011 Oct 06
4
[LLVMdev] TableGen and Greenspun
greened at obbligato.org (David A. Greene) writes:
> The problem I solved via multidefs was this: how does one write a set of
> Pat<> patterns in a generic way?
>
> For example, I want to be able to do this:
>
> defm MOVH :
> vs1x_fps_binary_vv_node_rmonly<
> 0x16, "movh", undef, 0,
> // rr
> [(undef)],
>
2008 Feb 02
0
Adding methods to Object in Rails -- WARNING
I wanted to do:
foo.wrap
and wrap would go to a specialized wrap for some types of foo and a
general Object#wrap for all the others.
So I added wrap to Object
class Object
def wrap
self
end
end
This worked except for objects which are actually AssociationProxy
objects pretending to be some other object. The reason is that
AssociationProxy removes all but a few methods from itself.
2007 Jun 04
1
acts_as_rateable in Beast
I''m trying to implement acts_as_rateable to my Beast installation to
give users the option to rate posts (like reddit). I chose
acts_as_rateable as it supposedly easily allows reddit-type voting but
I''m having some problems setting it up and the documentation seems
outdated.
(http://www.juixe.com/techknow/index.php/2006/07/05/acts-as-rateable-plugin/)
So far, I''ve
2007 Mar 16
1
Polymorphic find_or_create bug
Today I just spent 3 hours (and before a demo!) trying to figure out
why my polymorphic association fields were breaking.
Turns out someone else put in a patch for this 6 months ago. I''m not
sure if its the same solution I''d use... I''d rather find_or_create
attempt to use AssociationProxy#build if its available and only
Base#new if we''re not on a proxy.
2011 Mar 29
0
Issue / code smell in AssociationProxy
I came across an issue in my code and after a hard debug session I
found something that smells.
First the context of my issue. I have a AR object that has a
polymorphic belongs_to currently tied to nothing, I want to dump it to
YAML.
record.to_yaml
This raises the following exception:
TypeError: wrong argument type nil (expected Data)
from
2006 Mar 28
12
cached-model broken with Rails 1.1
It looks like cached-model is broken again under rails 1.1. Can anyone
confirm? Note that the exception below indicates it''s trying to treat
CachedModel as the class name of the model, rather than using the proper
class name (which is Entry in this case, and the table called entries).
This is a model using Single Table Inheritance and acts_as_tree, and
worked just fine under 1.0 and
2008 Apr 11
1
polymorphic associations wrong when used with inherited class?
Consider the following:
class Event
belongs_to :event_object, :polymorphic => true
end
class Asset < ActiveRecord::Base
end
class EventedAsset < Asset
has_one :event, :as => :event_object
end
EventedAsset.find(:first).event generates the following SQL:
SELECT * FROM `events` WHERE (events.event_object_id = 1 AND
events.event_object_type = ''Asset'') LIMIT 1
2008 Nov 12
5
dynamic condition for has_one and eager loading issue
Hi,
I ve defined the following relation in one of my models with a dynamic
where condition:
has_one :selection,
:foreign_key => ''object_id'',
:conditions => ''selection_type = 1 and account_id = #
{self.send(:account_id)}''
That works perfect, however when I try to eager load that relation I
am getting the following error when doing a
2011 May 23
0
Fallback for partial_paths on rendering process
Hi, I have an application that uses single table inheritance.
Very simple stuff:
class Place < ActiveRecord::Base
class City < Place
lets say I have a City on the @place
whenever I try using the
render @place
I will get an error, saying the templace cities/city doesn''t exist
but I do have a places/place template.
Is the any nice way to add this fallback for the base_class
2006 Dec 28
2
STI, controllers and views
Hello,
I have set up that uses single table inheritance. I have a number of
model subclasses following the example in AWDWR that uses Manager <
Employee < Person.
First question. Do I need to create controller classes for each? I
don''t think I do because a single controller should be able to shunt the
data between the models and the views.
Second question. Say I have a view
2009 Sep 09
0
Rails 2.3.4 ActiveRecord association problem
Upgraded our app from Rails 2.2.2 to 2.3.4, and I''m now encountering
an error when adding a child to a parent.
Top of the stack:
wrong number of arguments (1 for 0)
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/
associations/has_many_association.rb:61:in `save''
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/
2008 Oct 29
5
Polymorphic Associations with inheritance
I have two models, Article and Post, that has many Comments. However,
both Article and Post are inherited from a BaseContent class like so:
class Article < BaseContent
has_many :comments, :as => :commentable
end
class Post < BaseContent
has_many :comments, :as => :commentable
end
and here''s my Comment model:
class Comment < ActiveRecord::Base
belongs_to
2006 Mar 16
1
Rails SQL generation (Firebird adapter) - can someone explain ...
I see some possible issues with the SQL that is being generated by the
firebird adapter.
Every SQL is being generated on the fly by concatenating strings.
Can someone please explain why the SQL is being generated the way it is?
I cannot use this in real life for a couple of reasons:
1. This introduces a security hole because a user, accidentally or
deliberately, could potentially submit a