Ruby On Rails Classroom image

Neha  Jaggi / 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
Neha  Jaggi

Skills    Ruby On Rails

Qualifications :- High School - , College/University - Graphic Era Hill University, Dehradun, College/University - ,
Location :-Dehradun,Dehradun,UTTARAKHAND,India
Description:-

Experienced Software Developer with a demonstrated history of working in the Information Technology and services industry. Skilled in Web Technologies (Ruby on Rails, PostgreSQL, php, Laravel and AJAX). 


Explore
 

  Students (0)