Posts

Showing posts with the label has many

Rich Association Traversal

Image
Greetings My Friend, We could gain the ability to add complexity   of other attributes and methods   inside our section edit's model,   we lost something at the same time.   We now have to go through an extra step   to get from one side of the association over to the other.   For example, in our simple, has and belongs to many join,   if we wanted to know all of the admin users   who could edit a page,   we could just request the array of admin users,   page dot admin users and we'd get back an array. It would reach across the join table   to the other side of the association   but in our rich join,   we can't just ask for section's admin users  because there is no direct relationship   between section and admin user.   There's a model that's in between now.   We can still do it,   we just have to go through that extra step   of going through the section edits   and looking up e...

One to Many Association

Image
Greetings Geeks, Let's  understand how to work with  one-to-many associations .   One-to-many associations are gonna be similar   to one-to-one associations,   but there are a few main differences that I wanna highlight.   First, one-to-many associations   are gonna be much more commonly used.   In a typical application, you'll rarely use one-to-one,   but you'll use one-to-many the most often.   Second, because we have one object related to many objects,   we're gonna use plural names.   That's both gonna be true when we define the association   and also when we call the methods on it. And third, the relationship   is going to return an array of objects back to us   instead of a single object.   And that just makes sense, right?   If we're going to have many records associated with it,   we're going to have to store those in an array   so that it can hold all of those records...