Hi,
Your first problem is pretty easy:
class Manifest < ActiveRecord::Base
has_many :organizations
belongs_to :default_organization, :class_name =>
"Organization",
:foreign_key => "default_organization_id"
end
as for your second problem, the docs state:
" If you wish to assign an object to a has_one
<http://rails.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html#M000396>
association without saving it, use the association.build method
(documented below). "
Kind regards,
Flurin
Björn Weide wrote:
>Hi all,
>
>I have just started using Rails and are now trying to model a more complex
>application to evaluate the framework.
>
>I have 2 entities, Manifest and Organization. Manifest "has_many"
Organizations
>and a Organzation "belongs_to" a Manifest. It works fine so far,
but the model
>has a little extra: Manifest has a to-one-relationship to a single
Organization
>called default_organization (the Organization is yet in the organizations
>collection). How I would model this?
>My first thought was a "has_one" association, but the
default_organization_id is
>in the Manifest entity. I had changed it in a belongs_to, but it doesnt work
too
>(and is wrong in my opinion). The relationship is only a helper relationship
for
>smoother handling. Because the organization is already in the collection, it
>must not be saved when present in the default_organization relationship. Is
that
>possible?
>
>Regards,
>Björn
>
>_______________________________________________
>Rails mailing list
>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
>http://lists.rubyonrails.org/mailman/listinfo/rails
>
>