Displaying 20 results from an estimated 2000 matches similar to: "Self-referential habtm with condition is broken"
2005 Mar 04
3
optimization
Ok, so, I''ve written my first app in rails. It''s pretty nifty. Only
one problem. Slower than you could possibly comprehend.
Processing PersonController#show (for 67.138.254.231 at Thu Mar 03
21:04:16 Eastern Standard Time 2005)
Parameters: {:id=>"1", :controller=>"person", :action=>"show"}
[4;35mPerson Load (0.219000) [0;37mSELECT
2006 Aug 14
1
2 foreign keys to one table
Hi,
I have a messaging class that has to relationships to one table
belongs_to :user, :foreign_key => "from_id"
belongs_to :user, :foreign_key => "to_id"
At the min I can specify message.user.login and it will return the
username of last relationship to that table.
how can I get it to bring back both references
ie message.from.login and message.to.login
thanks
scott
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
2005 Dec 19
4
need some help designing my messaging system
I am trying to create a messaging system for my users but I''m having a
hard time designing my db. This is what i have in mind, but I am not
sure if its the best approach.
user has_one inbox
user has_one outbox
inbox has_many messages
outbox has_many messages
inbox table
user_id
outbox table
user_id
messages table
box_id (refers to either inbox or outbox - how?)
from_id
to_id
2007 Jul 26
1
Bi-directional self-referential HABTM
Hi,
I''m having a little trouble figuring out how to make a self-
referential HABTM bi-directional.
I have a Employee class. Each employee can have a couple of bosses,
who are also employees. The employee class has the following HABTM:
has_and_belongs_to_many :bosses, :class_name =>
"Employee", :join_table => "bosses_courses", :association_foreign_key
=>
2006 Mar 05
1
Help with Self-Referential HABTM
With the help of the Rails Recipes have got a self-referential HABTM
relationship working, but I''m really struggling with getting a new entry
from a form accepted. i should say here that the form is also submitting
info for the join table too.
So in my model I have:
class Type < ActiveRecord::Base
has_and_belongs_to_many :subtypes,
:class_name => ''Type'',
2006 May 02
0
Self-referential MtoM implementation
ok, guys i have followed the self referential recipe from the book it
works perfect but now i have some doubts, at the end the model are
modified to force the user beign added as a friend that add too who are
adding him so how i can make that the full relationship doesn?t be
complete until the friend beign added approves it(talking in the
implementation of the code of course)?
by the way,
2006 Jan 19
5
Multiple HABTM relationships with self ???
I need to have a table related to itself via a join table. Will HABTM
support this? That is:
class Recipe < ActiveRecord::Base
has_and_belongs_to_many :recipes, :join_table => "recipes_recipes"
end
More importantly -- how does RoR support MULTIPLE self-joins? I.e., to
relate the table to itself via multiple join tables.
SFAIK, HABTM won''t support multiple
2006 May 16
4
Problems with multiple ''id'' columns in a join_table
I have a problem declaring a relationship through a join_table ; the SQL
generated by ActiveRecord is correct, but there are two columns called
''id'', and the final object gets the ''wrong'' column ...
Here''s a more detailed description of the data, code, and problem :-
There''s a People table, with id, name, and a few things.
Also a
2006 Jan 19
0
Help with nested HABTM relationship
Hi,
I am trying to perform a query with ActiveRecord that I want to put into
a Rails application later. For now I just wrote it within a plain old
Ruby script for easier testing.
I am working with an existing database so I had to map some foreign keys
myself. As you can see from the models below, the database has a
structure of
Prospectlists <=habtm=> Contacts <=habtm=> Accounts
2006 Apr 27
0
last stupid question today
(well, from me anyway. I promise)
Trying to follow the "Self-referential Many-to-Many Relationships" recipe
from the Rails Recipes book.
This is what I''m doing: Tasks can have a predecessor relationship with each
other. My Task class has this:
has_and_belongs_to_many :predecessors,
:class_name => "Task",
:join_table => "predecessor",
2007 Oct 22
1
self-referential habtm: why are my keys null?
I''m trying to set up a directional self-referential HABTM to represent
an arbitrary semi-hierarchical structure; it works for any data
prepopulated into the db, but when I try to create a new relationship,
I just get NULLs in both key columns (or 0''s if I turn on the no-null
constraint).
Here are the migrations:
class CreateNodes < ActiveRecord::Migration
def self.up
2006 Mar 15
3
Self-referential join model does not work
I have been trying to model a labeled graph using ActiveRecord (trunk
version). Basically, I have a ''Node'' model which represents a node linking
to other nodes. Links (aka edges) are labeled (i.e., have a ''label''
attribute and other behavior). Thus I decided to model edges as an ''Edge''
model and use a ''has_many :trough''
2005 Oct 05
0
has_and_belongs_to_many on legacy DB
I am working with mapping ActiveRecord onto a legacy database. All is going
well (using set_table_name, set_primary_key, etc), but I can''t get my
many<=>many relationships to work.
My contrived example of the situation:
Student has_and_belongs_to_many Teachers. This is mapped via table
student2teacher where the foreign keys are studentId and teacherId. The
primary key in Student
2007 Nov 30
0
cross sell products - Options_from_collection_select ?
Hi
I have collected some code for cross sell products on this website.
CREATE TABLE products (
id INT NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
PRIMARY KEY (id)
);
INSERT INTO products VALUES (1, ''alpha'');
INSERT INTO products VALUES (2, ''beta'');
INSERT INTO products VALUES (3, ''gamma'');
CREATE TABLE cross_sells (
product_id
2006 Jan 06
2
Re: Some advice on DB modeling
I have more or less the same problem. I''m trying to build a system where
users can enter their friends. But the solutions seems not to work for me.
I used same sql:
CREATE TABLE `friends` (
`user_id` int(11) NOT NULL default ''0'',
`friend_id` int(11) NOT NULL default ''0'',
KEY `user_id` (`user_id`),
KEY `friend_id` (`friend_id`),
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
2010 Jun 08
3
partial matches across rows not columns
Hi R users,
I am trying to omit rows of data based on partial matches an example of my
data (seal_dist) is below:
A quick break down of my coding and why I need to answer this - I am dealing
with a colony of seals where for example A1 is a female with pup and A1.1 is
that female's pup, the important part of the data here is DIST which tells
the distance between one seal (ID) and another
2006 Feb 21
3
HABTM :insert_sql help
Hi all,
I''m working with a legacy sqlserver db and I''m trying to override the
insert sql in as defined in the HABTM method below(becasue the join
has three primary keys), but I''m getting the error: ''undefined local
variable or method `record'' for Project:Class''
has_and_belongs_to_many :people,
:class => ''Person'',