similar to: Self-referential has_many :through relationship

Displaying 20 results from an estimated 600 matches similar to: "Self-referential has_many :through relationship"

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 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
2007 May 10
5
Pagination has many through problems
I have searched for days for an example that demonstrates what i would like to do, and this morning i thought i''d worked it out, but no....here''s what i have: Controller ========== class ProfilesController < ApplicationController def friends current_user.profile.friends end def list_friends @profile_pages, @profiles = paginate( friends, :per_page => 10) end end
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 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 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.
2009 Aug 15
4
Isn't there any performance issue when saving serialized attributes every time?
In edge rails, serialized attributes are saved every time no matter they are changed or not: def update_with_dirty if partial_updates? # Serialized attributes should always be written in case they''ve been # changed in place. update_without_dirty(changed | (attributes.keys & self.class.serialized_attributes.keys)) else
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 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
2009 Jun 14
6
Unable to make observe_field work
I can''t make it work. <%= text_field_tag :friend %> <%= observe_field :friend, :url => friendships_url, :on => :click %> <%= javascript_include_tag :defaults %> Raises the error:Can''t find variable Form. The generated html is: <input id="friend" name="friend" type="text" /> <script
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
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,
2010 Oct 12
2
STI and :through, not working?
Artist.first.medias returns all medias. Media is an STI. Media can be video or painting. How do I return all paintings of an artist? Only paintings, not videos? In my Artist model, I tried putting: has_many :paintings, :through => :medias In console, I do: Artist.first.paintings.all And I get: ActiveRecord::HasManyThroughSourceAssociationNotFoundError: Could not find the source
2006 Jun 23
2
polymorphic challenge
Hello All, I have a little challenge and I am not sure if this is even possible I am working on a dating/event site and few functionalities are similar that I want to centralize them. We have users which can have - favorite users - interest list - blocked users All these relations are like; User <-> Relation <-> User I was thinking I could have a class called Relation (with a
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,
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(
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 Jun 19
3
Strange behavior of :through association.
class Host < ActiveRecord::Base belongs_to :person end class House < ActiveRecord::Base has_many :people, :dependent => true has_many :hosts, :through => :person end class Person < ActiveRecord::Base belongs_to :house has_many :hosts, :dependent => true end Now when I try to do: @hosts = House.find_by_id(params[:namas]).hosts from my controller I get this: