Ruby On Rails Lesson
When constructing data models for web applications, it is essential to be able to make associations between individual models. In the present case, each micropost is associated with one user, and each user is associated with (potentially) many microposts—a relationship seen briefly in Section 2.3.3 and shown schematically in Figure 10.2 and Figure 10.3. As part of implementing these associations, we’ll write tests for the Micropost model that, unlike Listing 10.2, are compatible with the use of attr_accessible in Listing 10.7.
Using the belongs_to/has_many association defined in this section, Rails constructs the methods shown in Table 10.1.
Note from Table 10.1 that instead of