Ruby On Rails Classroom image

Neeraj  Amoli / Professional / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  |1 | 2 | 3 | 4|Last
Lessons:- Followed users

  Followed users

We come now to the heart of the Relationship associations: followed_users and followers. We start with followed_users, as shown Listing 11.9.

 

The implementation uses has_many through for the first time: A user has many following through relationships, as illustrated in Figure 11.7. By default, in a has_many through association Rails looks for a foreign key corresponding to the singular version of the association; in other words, code like

has many :followeds, through: :relationships

 

would assemble an array using the followed_id in the relationships table. But, as noted in Section 11.1.1, user.followeds is rather awkward; far more natural is to use ‘‘followed users’’ as a plural of ‘‘followed,’’ and write instead user.followed_users for the array of followed users. Naturally, Rails allows us to override the default, in this case using the :source parameter (Listing 11.10), which explicitly tells Rails that the source of the followed_users array is the set of followed ids.

 

 
 
 
image
Neeraj  Amoli

Skills    Ruby On Rails

Qualifications :-
Location :-Dehradun,Dehradun,Uttrakhand,India
Description:-

I have 3 year experience as a Software Engineer. My Skilled are Android Development (Java), ROR Development .   


Explore
 

  Students (0)