Displaying 20 results from an estimated 300 matches similar to: "self-referential habtm: why are my keys null?"
2006 May 17
0
acts_as_versioned with lock_version bug?
Hello.
The acts_as_versioned plugin works fine ... till the adjunction
of optimistic locking via the lock_version table column.
Here is the problem description:
Without optimistic locking things are fine:
# ++++ The table creation migration ++++
% cat db/migrate/001_create_tables.rb
class CreateTables < ActiveRecord::Migration
def self.up
create_table :softwares,
2006 May 07
1
Anyone care for a braindump?
I have this problem with records that have to be alligned on end- and
startdate. I came up with the following. but am not convinced that this
is the best way to tackle this problem. Anyone care for a braindump?
def head_to_tail
# Remove days that have startdate >= self.startdate AND enddate <=
self.enddate
#
# before after
#
# |=====| |=====|
2007 Nov 14
1
has_many_polymorphs and acts_as_list ?
First, BRAVO for this wonderful plugin: has_many_polymorphs ! Now my
problem:
4 models : Collection, Page, Fragment, Belonging (which is the join
table):
1 class Collection <
ActiveRecord::Base
2 has_many_polymorphs :elements,
3 :through => :belongings,
4 :from => [:pages, :fragments, :collections],
5 :as => :collector,
6 :parent_order =>
2006 Mar 25
0
Self-Referential Many-To-Many relationships where the relationship itself has data.
Trying to model a bunch of users that have friends that are other
users. clearly a job for has_and_belongs_to_many, but the trick is,
they have ratings for their friends. I have gone through the Rails
Recipes book, and it seems like I''m trying to combine the
self-referential many-to-many recipe (12) and the many to many
relationships where the relationship itself has data recipe (16). So
2006 Jan 06
3
Flashing Window in Quicken
Wine version: all
Linux version: Fedora 3 and Gentoo 2.6.14
Symptom: When running quicken, opening the "Split costs"
dialog causes the program to go into an infinite loop,
flashingthe window to proper size then minimized and back
again, as fast as the display will allow.
It appears that the window is opened and the program
attempts to flash the caret but access is denied to
2012 Mar 21
1
Using extract function for dates in sqldf
I'm trying to use sqldf to query for the earliest date of a blood test when
patients have had multiple tests in a given year. My query looks like this:
test11 <- sqldf("select CHILD_ID, min(SAMP_DATE)
from lab
group by CHILD_ID
having extract (year from SAMP_DATE) = 2011")
SAMP_DATE has class "date." I get the error
2008 May 27
2
HABTM using two columns
Hi all,
I was wondering whether anyone could guide me to docu and code
examples how to create and use a has_and_belongs_to_many relationship
with a joining table where TWO columns are used to identify the
relation to TWO alternative tables.
Example:
table 1: mothers [mother_id, name]
table 2: fathers [father_id, name]
table 3: children [child_id, name]
joining table 4: children_parent
2008 Mar 28
0
Problems with URL encoding
Hi
I have a problem when sending parameters from link_to_remote. My link
code:
<%= link_to_remote "Remove",
:url => object_relation_path(
:id => 0,
:object_relation => {
:parent_id => @product.id,
:parent_type => "Product",
:child_id => content_object.id,
:child_type => "ContentObject",
2006 Feb 25
0
self referential habtm using join tables
All:
I have been working on making a self-referential habtm relationship
that uses a join model because I want to store info about the
relationship. I have been using two sections from Chad Fowler''s "Rails
Recipes" as a guide, "Self-referential Many-to-Many Relationships" and
"Many to Many Relationships Where the Relationship Itself has Data".
So far I have
2006 Feb 27
0
self-referential many-to-many using a join model
Hello!
I have been working on making a self-referential habtm relationship
that uses a join model because I want to store info about the
relationship. I have been using two sections from Chad Fowler''s "Rails
Recipes" as a guide, "Self-referential Many-to-Many Relationships" and
"Many to Many Relationships Where the Relationship Itself has Data".
So far I
2007 Feb 12
2
Objects in Arrays? Allowed, right?
Hi:
I''m trying to manually append objects to an instance variable that is
just an array of objects. Here''s my controller code:
@tasks = Task.find(:all, :conditions => "entity_id =
#{session[:user].id}")
for t in @tasks
if Subtasks.find(:first, :conditions => "child_id = #{t.id}") != nil
@mtasks << t
end
end
However, when I execute, I
2007 Feb 04
2
Per activerecord object callbacks (aka: should I have gone to bed hours ago?)
First of all, I should have gone to bed a long time, so please be
forgiving with regards to what will follow :)
So I''ve been working all day on a rails project that needs to go out
soon, and I thought I would try to refactor a has_many relationship to
a has_and_belongs_to_many relationship (using has_many :through).
However, I then realized that I would loose a lot of the simple beauty
2005 Jul 21
1
Self-Referencing Tables and Other DB Complexities
How well does Rails deal with ActiveRecord classes mapping to
self-referencing tables and other more interesting database
complexities?
i.e. Employees table with supervisor_id and mentor_id both
self-referencing Employees on the primary key "id"
or Categories table with relation table (Parent_Child_Categories) with
foreign keys parent_id and child_id both referencing Categories.id
2006 Aug 09
0
admin.create error in devel. console
im getting this error when i attemp to create an admin account in the
devel. console... first is the script im trying to run and then the
error... full output:
>> @a = Admin.create :fullname => "Zack", :email => "zack@xxxxxx.com", :capabilities => {"member_info" => "1", "close_xxxxxx"=>"1",
2006 Jun 07
1
Setter that converts a float attribute to integer
Hi,
I have some problems with an application where I''m using custom
accessors to do currency conversions. In my model, I have a price
attribute in the database that stores the value in cents, to avoid
future problems with float arithmetic and round. But at the views, I
would like to show the price in euros, with decimal for the cents. So
I defined a new attribute called price_in_euros,
2006 Apr 20
4
Many to Many Category structure with itself
Basically, I''m trying to have a table called "categories" have a many to
many relationship with itself. But I also want each catagory to be able
to be "copied" into another category so it is essentially a child
category to more than one parent. To me the obvious way of doing this is
by creating another table called category_maps (and a model called
CategoryMap).
2006 Jun 07
2
Problem with a setter that converts euros to cents
Hi,
I have some problems with an application where I''m using custom
accessors to do currency conversions. In my model, I have a price
attribute in the database that stores the value in cents, to avoid
future problems with float arithmetic and round. But at the views, I
would like to show the price in euros, with decimal for the cents. So
I defined a new attribute called price_in_euros,
2006 Mar 24
6
Should counter_cache fields be saved in the database?
As far as I can tell, the counter_cache option on a belongs_to model
doesn''t actually save anything in the database. For example, I have
the following models:
class Parent < ActiveRecord::Base
has_many :children,
:conditions => "deleted_at IS NULL"
end
class Child < ActiveRecord::Base
belongs_to :parent, :counter_cache => true
end
With the following
2006 Aug 15
0
has_many relationships and minimums
Hi,
New to Rails and the list.
Quick questions regarding has_many relationships that require at least 1
child.
I''m aware of validate_size_of and use this to make sure that the parent
is not saved without at least one child. Question is, is there some
Rails magic to help when removing children to ensure the last one is not
removed? Currently I''m calling something like this in my
2006 Mar 08
0
acts_as_tree circular reference
my application is using acts_as_tree to create a directed graph.
Everyone would work fine, except that nothing prevents the user to
create a circular reference:
>> item.parent=child
>> item.save
=> true
>> child.parent=item
>> child.save
=> true
I checked in the database, and there it is: an item that has as parent
its own child!
item.parent_id = child_id
I