*changes to one association will not be reflected in the other until reload.

On Thu, May 21, 2015 at 6:14 PM, Stewart Mckinney <[email protected]>
wrote:

> Create two associations with conditions on the parent table with
> conditions that point to each "type" of address.
>
> For instance:
>
> has_many :addresses
>
> has_one :primary_address,
> ->() do
>   where( :type => :primary )
> end,
> :class_name => Address
>
> This will make primary address accessible through addresses but also make
> it its own association ( so you can just pass that association to the form
> ).
>
> Be aware that changes to one association will not be reflected in the
> other. So if you change "primary_address", before you reload, the object in
> addresses which corresponds to your primary address will not have the
> changes you made to primary address. After you save/reload, they will.
>
> On Thu, May 21, 2015 at 6:00 PM, Walter Lee Davis <[email protected]>
> wrote:
>
>> Do these addresses have any difference besides being primary or
>> secondary? Are there extra fields in one that are not in the other? Or is
>> primary maybe a boolean on the address object?
>>
>> Walter
>>
>> On May 21, 2015, at 3:36 PM, Elizabeth McGurty <[email protected]>
>> wrote:
>>
>> > I have a parent table.  And associated with that parent table is two
>> possible addresses, a primary one and/or an alternative: (has_many and
>> accepts_nested_attributes_for).
>> >
>> > Rather than creating a second addresses table, I have used a flag,
>> address_type to distinguish primary from alternative, which will apparently
>> only be useful if I can create a condition on fields_for
>> >
>> > But now as I explore and research more, seems that I cannot create a
>> condition on fields_for addresses, type => 'alternative' or 'primary'.
>> >
>> > I want to utilize Rails associations... Should I just create tables:
>> primary_addresses and alternative_addresses?
>> >
>> > Thanks,
>> >
>> > Liz
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups "Ruby on Rails: Talk" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> an email to [email protected].
>> > To post to this group, send email to [email protected].
>> > To view this discussion on the web visit
>> https://groups.google.com/d/msgid/rubyonrails-talk/ae5620b7-a237-4ba2-ac52-1596fa3b7d8a%40googlegroups.com
>> .
>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ruby on Rails: Talk" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/rubyonrails-talk/35D23682-9E4B-4B3D-A985-FB12B485C269%40wdstudio.com
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CA%2BCQ937oq%3DBOx80eSnnqTxaYwid7D%2BaNzA6_m%2BQUi2vFWSi-JA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to