Ruby On Rails Classroom image

Anil  Bist / Professional / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2 | 3|
Lessons:- User/Relationship Associations

ince destroying a user should also destroy that user’s relationships, we’ve gone ahead and added dependent: :destroy to the association; writing a test for this is left as an exercise (Section 11.5).

      As with the Micropost model, the Relationship model has a belongs_to relationship with users; in this case, a relationship object belongs to both a follower and a followed user, which we test for in Listing 11.5.

 

To writethe application code, we definethe belongs_to relationship as usual. Rails infers the names of theforeign keys from the corresponding symbols (i.e., follower_id from :follower, and followed_id from :followed), but since there is neither a Followed nor a Follower model we need to supply the class name User. The result is shown in Listing 11.6. Note that, unlike the default generate Relationship model, in this case only the followed_id is accessible.

 

The followed association isn’t actually needed until Section 11.1.5, but the parallel follower/followed structure is clearer if we implement them both at the same time.

     At this point, the tests in Listing 11.2 and Listing 11.3 should pass.

$ bundle exec rspec spec/

 

 
 
 
image
Anil  Bist

Skills    Ruby On Rails

Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,
Location :-Dehradun,Dehradun,Uttarakhand,India
Description:-

I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore

 

  Students (0)