Displaying 20 results from an estimated 1000 matches similar to: "Association of table to itself"
2006 Aug 15
2
How to access attribute in a self-referential many-to-many relationship
Hello List,
I created a self-referential many-to-many relationship (as described
in the book Rails recipe #18), where I have a model that has
many-to-many relationships with itself. In this case, it''s person who
can become friends. The join table looks like this:
mysql> select * from friends_people;
+-----------+-----------+-----------+
| person_id | friend_id | confirmed |
2006 Apr 20
2
table that have many-to-may relationship to itself
In a social netowrk data model, users belongs other users, and can have
many friends as users, so it is a many to many relatioship.
the class definition could be
class User < ApplicationController
has_mang_ang_belongs_to users
But how it looks like in the mysql database tables in a "joined" users
table.
The question really is: what is the table looks like when a model has
2006 Aug 02
2
Self-Referential has_many :through
Hello all.
I am trying to create a self-referential has_many :through. I used the
following site as a guide
http://blog.hasmanythrough.com/articles/2006/04/21/self-referential-through
but it still doesn''t appear to be working. I have two models. Person and
Relationship. A person has many contacts (Which is another person)
through relationships
class Person < ActiveRecord::Base
2006 May 28
7
Self-referential has_many :through relationship
Hi,
I have a self-referential has_many :through relationship setup to
track relationships between users. Basically relationships are
modeled as a join table with an extra column ''relation''.
create table relationships (
user_id integer unsigned not null,
friend_id integer unsigned not null,
relation char(1) not null,
)
--- relations ---
f = friend
r = request to
2006 Jul 28
7
Uploading 2+ files simultaneously
I''m having trouble uploading 2+ files simultaneously (from different
client machines)...
the upload page just hangs...
I''m running...
- ruby 1.8.4 (2005-12-24) [i686-linux]
- rails 1.1.4
- red hat el 4
- apache
- fcgi (0.8.7, 0.8.6.1)
- firefox 1.5.0.5
- httpd.conf
<IfModule mod_fastcgi.c>
FastCgiIpcDir /tmp/fcgi_ipc/
AddHandler fastcgi-script .fcgi
FastCGIConfig
2006 Mar 31
6
Adding objects to a :through association
So I''m one of those nasty people building a self-referential
habtm-like Association using the funky new :through stuff. This is
about users having friends, so here''s my user.rb:
class User < ActiveRecord::Base
has_many :friendships, :foreign_key => ''user_id''
has_many :friends, :through => :friendships, :source => :friend
end
And here''s
2006 May 16
2
Validate Before Delete
I have an Order model with a ''status'' column. What I want to be able to do
is validate that the status of the Order is not completed before it is
allowed to be deleted. I tried the following method in my Model, but it
appears that this only works for an :update or :create on the record.
Anyone know how to do this, and if it should be in the model or the
controller?
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 21
7
Self-referencial habtm relationship
Heyo!
I am setting up a self-referencial habtm relationship with the users
of my app. I am using Chad Fowler''s "Rails Recipes" to get me started,
and everything works great with the join table "people_friends". I add
friends by doing somebody.friends << somebodyelse. However, with my
app, there is an approval process so my join table has columns
person_id,
2006 Jan 28
1
Advice on Optimization, and where to put what?
In my last post I was asking how I could check for the existance of a
record before inserting a new one and this was the helper method that I
was using to do this:
def already_friend_of?(friend)
begin
self.friends.find(friend.id)
true
rescue
false
end
end
I was told that this is not very efficient, as it hits the db every time
I call it. I completely agree and would like to
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 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 24
3
Merging two heavily referenced records into one
Here''s the situation: I have a "people" table whose "id" column serves
as a foreign key to several other tables (authorships, editorships,
members, users, etc.). Every now and then I will find two distinct
records in the "people" table that represent the same human being. They
generally differ by small differences in spelling but should really be
the
2006 Apr 03
1
has_many :trough with 2x the same table
I have a site where Users can become Friends with other Users. I used to do this with a habtm, but of course I want to stay up-to-date and convert this to a has_many :trough. Unfortunately I can''t get it to work.. the documentation on this feature is a bit sparse at the moment.
This is my old habtm:
has_and_belongs_to_many :friends, :join_table => ''user_friends'',
2008 Jan 23
1
Self-referential HABTM SQL mal-formed when updating record
Guys,
Anyone ever had this kind of problem with ActiveScaffold?
Cheers, Sazima
------------------------------------------------------------------------------------------------
What steps will reproduce the problem?
1. Create self-referential HABTM application (like the common "user
has friends" example)
2. Try to add more than 1 friend to a given user using ActiveScaffold.
What is
2010 May 24
3
ActionController::DoubleRenderError
def dispfriends
@myfriend=[]
@myfriendlogin = []
i=0
@currentgroup = Group.find_by_id(params[:groupid])
puts @currentgroup.id
@currentfriends=
GroupFriend.find_all_by_user_id_and_group_id(current_user.id,
@currentgroup.id)
for n in @currentfriends
@myfriend=n.friend_id
@myusers = User.find_by_id(@myfriend)
@myfriendlogin[i]=@myusers.login
puts @myfriendlogin[i]
i=i+1
respond_to do
2008 Aug 29
3
Many to Many Relationship with One Model
Hey everyone,
I''m working on allow users to follow other users in my app so they can
receive updates to what all their friends are doing (like Facebook/
Twitter). I''m wondering on how the relationship would be for the
model. Sounds like a HABTM type of association, but how would I go
about doing it for only one model?
Thanks,
Tony
2009 Feb 27
4
Optimize for loop / find last record for each person
I want to find the last record for each person_id in a data frame
(from a SQL database) ordered by date. Is there a better way than
this for loop?
for (i in 2:length(history[,1])) {
if (history[i, "person_id"] == history[i - 1, "person_id"])
history[i, "order"] = history[i - 1, "order"] + 1 # same person
else
history[i,
2006 Jul 17
14
REST Relationship Models
I''m trying to figure out an elegant way to do this:
I have the following three tables:
people, employer, employees
And consequently the following three models:
class Person < ActiveRecord::Base
end
class Employer < ActiveRecord::Base
has_many :employees
end
class Employee < ActiveRecord::Base
belongs_to :person
belongs_to :employer
end
I want to be able to say:
2007 May 16
5
drop a letter
hello,
how can I do to drop C from this character "C325" ?
_____________________________________________________________________________
[[alternative HTML version deleted]]