search for: friend_id

Displaying 20 results from an estimated 20 matches for "friend_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`), CONSTRAINT `friends_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`), CONSTRAINT `friends_ibfk_2` FOREIGN KEY (`friend_id`) REFERENCES `users` (`id`) ) My user.rb...
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 be a friend b = blocked My models look like this: class Relationship < ActiveRecord::Base belongs_to :user belongs_to :friend, :class_name => ''User'', :foreign_key...
2006 May 28
3
Association of table to itself
I''m curious what would be the best way to represent people and whether the person has someone marked as their friend. Here are my thoughts so far: People table - id - name Relationships table - person_id - friend_id Now my problem is I don''t know how to set up these associations (if this is even correct). Friend_id would be an id to someone else from the people table. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachme...
2009 Aug 15
4
Isn't there any performance issue when saving serialized attributes every time?
...ritten in case they''ve been # changed in place. update_without_dirty(changed | (attributes.keys & self.class.serialized_attributes.keys)) else update_without_dirty end end In out app, User model has a serialized attribute friend_ids, which is the id array of the user''s friends (used to be a friendships table, but when that table grew to tens of millions of records, we refactored it to a User''s attribute). The User model in our app is saved very frenquently, and many users have more than 1 handred friends, so...
2006 Mar 25
0
Self-Referential Many-To-Many relationships where the relationship itself has data.
...nds. 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 users have unique names, and friendships have user_id''s, friend_id''s, and ratings. And here''s the model code: class User < ActiveRecord::Base has_and_belongs_to_many :all_friends, :class_name => "User", :join_table => "friendships", :foreign_key => "user_id", :association_foreign_key =&...
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
2006 Jan 28
1
Advice on Optimization, and where to put what?
...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 do this in a more optimized way. I was told to create another method that reads all the friend_id''s of my user into an array and work on that array instead. I think this is a good approach, since I would have to hit the db just once to get that information and then use the array from then on. My question is.. how do I go about doing that and where would my code be? In the Model? In...
2006 Mar 31
6
Adding objects to a :through association
...''user_id'' has_many :friends, :through => :friendships, :source => :friend end And here''s my friendship.rb: class Friendship < ActiveRecord::Base belongs_to :user belongs_to :friend, :class_name => ''User'', :foreign_key => ''friend_id'' end Now, everything is working great as long as I create instances of Friendship "manually". Really no problems whatsoever, everything is working just perfectly. However, simply moving one user into another user''s list of friends does *not* seem to work: someone.fr...
2006 Aug 15
2
How to access attribute in 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 | +-----------+-----------+-----------+ | 1 | 2 | NULL | | 2 | 1 | NULL | | 1 | 3 | NULL | | 3 | 1 | NULL | and the people table is mysql> select * from people; +-------------+ | id | name | +----+...
2006 May 02
0
Self-referential MtoM implementation
...way, here is the code: class AddPeopleAndTheirFriendsRelationship < ActiveRecord::Migration def self.up create_table :people do |t| t.column "name", :string end create_table :friends_people do |t| t.column "person_id", :integer t.column "friend_id", :integer end end def self.down drop_table :people drop_table :friends_people end end class Person < ActiveRecord::Base has_and_belongs_to_many :friends, :class_name => "Person", :join_table => "friends_people", :association_foreig...
2006 Apr 03
1
has_many :trough with 2x the same table
...y 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'', :foreign_key => ''user_id'', :association_foreign_key => ''friend_id'', :class_name => ''Person'' I''ve tried various things, but I''m completely lost now. I looked at the :source option, but that doesn''t allow me to do this and the :class_name parameter doesn''t seem to work either. Any hints?
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 Jan 27
2
User.already_friend_of(friend)?
I have a User model who HBTM Friends (class User). I would like to check for the existance of a user in the friends table before actually adding them (in case they were already added as a friend.) I have a method called already_friend_of?(friend) defined in my User model, but I am not sure how to define this method. I simply want to check to see if one user is already a friend of another user
2008 Jan 23
1
Self-referential HABTM SQL mal-formed when updating record
...sing ActiveScaffold. What is the expected output? What do you see instead? 2+ friends related to the user. Instead I get a MySQL error: ActiveRecord::StatementInvalid (Mysql::Error: Duplicate entry ''4'' for key 1: INSERT INTO friends (`updated_at`, `id`, `user_id`, `created_at`, `friend_id`) VALUES (''2008-01-22 20:27:49'', 4, 2, ''2008-01-22 20:26:31'', 4)) What version (or revision) of the product are you using? 1.1.1 + Rails 2.0.2 (InstantRails 2 installation) --~--~---------~--~----~------------~-------~--~----~ You received this message because y...
2013 May 30
0
Import friends
Hi friends, I need send invitation to my facebook friends. i can import all my facebook friends. but when i send a message to particular user this message send all my friends. how can i solved it. Please help me. this is my code def facebook_invite friend_id= params[:mail] logger.debug(''CURRENT'') logger.debug( current_user.authentications[0][''token''] ) if( access_token = current_user.authentications[0][''token''] ) @graph = Koala::Facebook::GraphAPI.new(access_token) *@graph.ge...
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 |format| format.html { render :partial => ''users/dispfriends'', :locals => {:user => @myusers}} end end end Error: ActionController::DoubleRende...
2006 Feb 21
7
Self-referencial habtm relationship
...ng 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, friend_id, and approved. How do I control the "approved field"? When I add a friend, I want to set approved to zero, when they are approved, I want to set it to one. I played around with the arrays in console, but all that happened was approved was set to null. If I can''t figure out anothe...
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
2007 May 10
5
Pagination has many through problems
...0) end end Models ====== class Profile < ActiveRecord::Base has_many :friendships has_many :friends, :through => :friendships end class Friendship < ActiveRecord::Base belongs_to :profile belongs_to :friend, :class_name => "Profile", :foreign_key => "friend_id" end When accessing "http://localhost:3000/profiles/list_friends" i get the error: "#<Profile:0x10ee01b4>#<Profile:0x10ee018c>" is not a valid constant name! Any help gratefully recieved!! keith -- Posted via http://www.ruby-forum.com/. --~--~---------~-...
2006 Oct 31
5
conditional boost? friends to come up at top of search...
Hey guys, im trying to get my friends to come up at the top of the act as ferret search. I would query the whole result set first, then move my friends to the top, but the thing is, Im paginating my results and use the offset and limit parameters in the multi_search() function. Anyone know how to do this? Thanks in advance... -- Posted via http://www.ruby-forum.com/.