Displaying 20 results from an estimated 40000 matches similar to: "Has_one and Class Table Inheritance"
2005 Oct 27
0
has_one with Single Table Inheritance - NameError : uninitialized constant
I am having a problem with using SIngle Table Inheritance with a has_one
relationship, and I am at a loss of what could be causing it. Below is the
related code and the error message.
class User < ActiveRecord::Base
has_one :wishlist
end
class List < ActiveRecord::Base
belongs_to :user
end
class Wishlist < List
has_and_belongs_to_many :items, :class_name =>
2006 Jun 06
1
Please Help with single table inheritance relationships
I''ve been searching the web, wikis, and more, and I haven''t turned up
examples of how to have multiple entities in a single-table inheritance
related to anything.
I have an addresses table, but multiple entities can have Addresses:
both Person (which has 2 addresses) and Retailer. I''ve been told that I
need to use single-table inheritance, and this was my attempt:
2007 Apr 14
0
has_one with reference to the one stored in this object's table?
I''m trying to build a system for generically storing an object graph,
on top of AR itself. The idea is to define one base class, and use
AR''s automatic single table inheritance to have it create the right
class.
Here''s what I have so far:
table generic_objects:
id int(11) not null auto_increment primary key
type varchar(255)
table generic_fields:
id
2006 Jan 13
4
Single Table Inheritance (this is my 3rd post :( )
Hi Everyone,
I hope I get some feedback on my question. Here it goes.
I have a situation here, I have a company table and then using Single
Table inheritance it is of 3 types:
class Company < ActiveRecord::Base
end
class Vendor < Company
end
class Customer < Company
end
class Agent < Company
end
Now I have a active record Association
class QuoteSheet < ActiveRecord::Base
2006 Aug 30
1
Single Table Inheritance with self-referential join
Please tell me if this train of thinking makes sense, I need help on
solving this association model problem:
I am doing an app that creates and manages stereoscopic images, one
stereoscopic image is formed by two photos, say photo1 and photo2
The user uploads photo1 and then photo2 and gets a preview if he likes
the preview he/she authorizes it and gets a final stereoscopic image
All this
2005 Sep 29
0
Table relationships with single table inheritance
Hi,
How do I relate a table to another when one of the models uses single table
inheritance? Will this even work? This is the specific problem I am having:
There''s an "Address" model with "ShippingAddress" and "BillingAddress" as
subclasses. It looks like this:
class Address < ActiveRecord::Base
End
class ShippingAddress < Address
has_one :order
2009 Oct 05
0
ActiveRecord Polymorphic Inheritance
I am using RoR ActiveRecord polymorphic inheritance and was wondering
if it''s possible to access the base class'' association methods in the
invocation of either to_xml or to_json without having to depict the
base class data in the serialized string. Here are my classes:
# base class
class Asset < ActiveRecord::Base
belongs_to :resource, :polymorphic => true
2007 May 14
0
building and saving has_many and has_one relations
Hi,
I am very confused about an aspect of has_one and has_many relations,
with regard to using the build method, and saving the belongs_to side.
It''s a somewhat long post. so please bear with me :)
First let''s consider the has_one scenario. Let''s say I have a student
who must own exactly one car:
class Student
has_one(:car)
end
class Car
belongs_to(:student)
2006 Jul 17
2
Trouble with has_one
Hi,
I''m trying to write a blog application where each post has a single
header image associated.
My models:
----------
class Post < ActiveRecord::Base
belongs_to :blog
has_many :images
has_one :header
end
class Header < ActiveRecord::Base
file_column :image_path
end
class Image < ActiveRecord::Base
belongs_to :post
file_column :image_path
end
The controller targets I
2006 Feb 17
3
Using :include with has_one vs. has_many
While I''m happy to continue talking about the vagaries of Rails deployments, I
also need to actually build apps. :)
I may have discovered a bit of a problem with :include as it applies to has_one
associations. First, let me say that I''m a big fan of :include for reducing the
number of SQL calls. There are times when I wish it could go more than 1 step
away from the parent
2011 Jul 07
0
has_one through belongs_to
Hi.
My model data is the following:
- Place
- User
- Checkin
Instead of having a Checkin that belongs to both User and Place, I chose to
add another model, Program, that allows to list all the places a user can
checkin into, and also hide the checkins he''s no longer involved in (= the
user sign out of a specific program).
That give me crazy relationships:
Program has_many Checkin
2010 May 11
1
has_one/belongs_to -- accessing the subordinate
With a has_one/belongs_to relationship, what''s the best way to guarantee
that the belongs_to object gets created and is accessible alongside the
has_one object? I *think* the after_create callback is a good choice,
but I discovered an oddity while trying it.
F''rinstance, if every horse has a carriage:
============
ActiveRecord::Schema.define do
create_table(:horses) {|t|
2006 Apr 17
2
has_one problem in a form
Hello all,
I have a syntax question. How does one refer to a field brought in via a
has_one/belongs_to relationship in a form helper? Basically, I have two
models:
class Resource < ActiveRecord::Base
has_one :other_thing
end
class OtherThing < ActiveRecord::Base
belongs_to :resource
end
It has the normal id-resource_id foreign key relationship. OtherThing has
two fields, plus the
2006 Mar 14
4
has_one
I''ve got an order model that stores order data.
One piece of data is a credit card type, which is a digit 1,2 or 3.
I have a cardType model that has an id, shortName and LongName for the
credit card merchant (visa, mastercard, amex).
I want to be able to say: order.cardType.shortName, but can''t seem to
get has_one working. It works with has_many and a finder_sql statement
on
2007 Aug 21
4
[AWDwR] Confused about has_one and has_many
Heya everyone!
I am quite new to Rails and I am reading AWDwR. I am at Task E "Check
Out!". I understand it quite well, but I have a problem with the last
playground exercise: Add a Table which contains the payment types.
All goes well, but I am not sure whether I should use has_many or
has_one(as in the Playground wiki at
http://wiki.pragprog.com/cgi-bin/wiki.cgi/PT-E-3).
I use the
2008 Apr 29
4
Default values for belongs_to and has_one
There really doesn''t seem to be a *declarative* way to define a default
value for belongs_to and has_one associations
class Person < ActiveRecord::Base
belongs_to :address
end
p = Person.new
p.address.city = ''Atlantis'' # Bummer!
Of course, there''s an easy way to avoid this
class Person < ActiveRecord::Base
belongs_to :address
2006 May 16
1
:conditions on has_one realationship
Hi there,
I''m currently building a membership application and I want to be able
to select, not just all the memberships, but the most current
membership from the database on a per user basis. I have linked the
tables as shown:-
class Membership < ActiveRecord::Base
belongs_to :payment
belongs_to :person
end
class Person < ActiveRecord::Base
has_many :memberships
2006 May 12
1
can I fake has_one :through?
I''m having a difficult time wrapping my head around a set of models
and their associations and seeing how they map into Rails. I''ll try
to lay out my problem using the has_many and belongs_to structures. I
have a RuleSpace, a Rule, and a Subject.
A RuleSpace has_many Rules
A RulesSpace has_many Subjects through Rules
A Rule belongs_to (many) RuleSpaces
A Rule has_many
2008 Sep 29
1
has_one :through with :source. How to alias association?
Hi to everyone,
I have the following models:
class Attachment < ActiveRecord::Base
has_attachment :content_type => [:image, ''application/pdf''],
:max_size => 3.megabytes,
:path_prefix => ''../private/attachments'',
:storage => :file_system,
:processor => :rmagick,
2006 Jul 06
4
has_one, belongs_to - I am just not getting it
Let me preface by saying i''m a total noob at ruby/rails. :-)
For some reason, I am just not grasping the concept of has_one &
belongs_to...
I''m working on a project that includes user authentication, and 3
different types of user profiles.
User profiles are either "fan", "band", or "venue" objects, and user
logins are "user"