Hi,
I''d be sooo happy I any of you could help me out with a problem
I''m
currently stuck with :-)
### Basic info ###
I''m on Rails 2.3.5 and love using the formtastic formbuilder :-)
### What I''m working on ###
I''m currently trying to build a little
demo app where my friends and I are able to manage all the things we
borrowed each other. (I know there are apps like this on the internet,
I just wanted to built my own to get used to rails :-)).
So wanted to build a form where I can enter:
- the name of the thing I''m borrowing to someone
- who I''m borrowing the thing to
--> I set up the Models
User
    name ..... (default hobo user model)
Loan
    name:string
    reminder:date
### PROBLEM ###
Now I wanted to set up 2 relations between the model.....
- Who is giving away the loan
- Who borrows the loan
????--> What do you think would be the most clever way to set up these
relations for my "use case"?????
### Idea 1 ###
Loan
   belongs_to :lender, :polymorphic => true
   belongs_to :borrower, :polymorphic => true
User
   has_many :loans, :as => :lender
   has_many :loans, :as => :borrower
--> Does this work anyway???????? (User.loans would be ambiguous,
right?)
--> how could I create a form to create a new Loan and select the
borrower from a select (the app would assign me as the lender in the
controller or by hidden field I guess)
### Idea 2 ###
Loan
    has_many :loan_assignments, :dependent => :destroy
    has_many :users, :through => :loan_assignments, :accessible =>
true
User
    has_many :loan_assignments, :dependent => :destroy
    has_many :loans, :through => :loan_assignments
--> How do I restrict the form, so I can only select 1 borrower
in /loans/new ???
-------
P.S. Sorry for my English, it''s not my native tongue :-)
-- 
Posted via http://www.ruby-forum.com/.
-- 
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi,
I''d be sooo happy I any of you could help me out with a problem
I''m
currently stuck with :-)
### Basic info ###
I''m on Rails 2.3.5 and love using the formtastic formbuilder :-)
### What I''m working on ###
I''m currently trying to build a little
demo app where my friends and I are able to manage all the things we
borrowed each other. (I know there are apps like this on the internet,
I just wanted to built my own to get used to rails :-)).
So wanted to build a form where I can enter:
- the name of the thing I''m borrowing to someone
- who I''m borrowing the thing to
--> I set up the Models
User
    name ..... (default hobo user model)
Loan
    name:string
    reminder:date
### PROBLEM ###
Now I wanted to set up 2 relations between the model.....
- Who is giving away the loan
- Who borrows the loan
????--> What do you think would be the most clever way to set up these
relations for my "use case"?????
### Idea 1 ###
Loan
   belongs_to :lender, :polymorphic => true
   belongs_to :borrower, :polymorphic => true
User
   has_many :loans, :as => :lender
   has_many :loans, :as => :borrower
--> Does this work anyway???????? (User.loans would be ambiguous,
right?)
--> how could I create a form to create a new Loan and select the
borrower from a select (the app would assign me as the lender in the
controller or by hidden field I guess)
### Idea 2 ###
Loan
    has_many :loan_assignments, :dependent => :destroy
    has_many :users, :through => :loan_assignments, :accessible =>
true
User
    has_many :loan_assignments, :dependent => :destroy
    has_many :loans, :through => :loan_assignments
--> How do I restrict the form, so I can only select 1 borrower
in /loans/new ???
-------
P.S. Sorry for my English, it''s not my native tongue :-)
-- 
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tue, Jan 19, 2010 at 12:38 PM, tiekuhn <nilskuhn-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I''d be sooo happy I any of you could help me out with a problem I''m > currently stuck with :-) > > ### Basic info ### > I''m on Rails 2.3.5 and love using the formtastic formbuilder :-) > > ### What I''m working on ### > I''m currently trying to build a little > demo app where my friends and I are able to manage all the things we > borrowed each other. (I know there are apps like this on the internet, > I just wanted to built my own to get used to rails :-)). > > So wanted to build a form where I can enter: > - the name of the thing I''m borrowing to someone > - who I''m borrowing the thing to > > --> I set up the Models > User > name ..... (default hobo user model) > > Loan > name:string > reminder:date > > ### PROBLEM ### > Now I wanted to set up 2 relations between the model..... > - Who is giving away the loan > - Who borrows the loan > > ????--> What do you think would be the most clever way to set up these > relations for my "use case"????? > > ### Idea 1 ### > Loan > belongs_to :lender, :polymorphic => true > belongs_to :borrower, :polymorphic => true > > User > has_many :loans, :as => :lender > has_many :loans, :as => :borrower > > --> Does this work anyway???????? (User.loans would be ambiguous, > right?) > --> how could I create a form to create a new Loan and select the > borrower from a select (the app would assign me as the lender in the > controller or by hidden field I guess) > > ### Idea 2 ### > Loan > has_many :loan_assignments, :dependent => :destroy > has_many :users, :through => :loan_assignments, :accessible => > true > > User > has_many :loan_assignments, :dependent => :destroy > has_many :loans, :through => :loan_assignments > > --> How do I restrict the form, so I can only select 1 borrower > in /loans/new ???### Idea 3 ### Loan belongs_to :lender, :class_name => "User" belongs_to :borrower, :class_name => "User" User has_many :lendings, :class_name => "Loan", :foreign_key => :lender_id has_many :borrowings, :class_name => "Loan", :foreign_key => :borrower_id -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.