ruby - Many to many and one to many association between same models -
itemprop = "text">
I am creating a simple synatra app for my ORM, / P>
- There can be multiple users of an event, one of which is "owner".
- Users have multiple instances,
Here is a simplified version of my schema / model definitions:
class users & lt; Sequel :: Models (: Users) many_to_many: Event_it_on: Event and Class Event & lt; Sequel :: Models (: Events) many_to_many: Users multiple_to_one: User End provides a link between # users and event # Eg. Event.users or user.events # I am unsure how it is necessary :) db.create_table: events_users primay_key: id foreign_key: event_id ,: events foreign_key: user_id ,: users end
This allows me to get users connected to an event, or users who are connected to a user, but I am struggling to express the "ownership" of an event. It seems that the following pseudocode will work:
my_user = User.all.first Owned_Avents = Event.where (user_id = my_user.user_id)
that Two questions lead to:
- Is the way I am using Assurance, does that mean?
- How do I express ownership of an event in relation to Sequel's Association model?
Something like this:
class event many_to_one : Owner, class = & gt; User: many_to_many: user and class user one_to_many: own_events, class =>: event :: key = & gt ;: owner_id many_to_many: event end
< P> You must be added to the Ownership / ID> field Event
table. Usage:
User = User. First event = Event.new (: title = & gt; 'new event') events.add_owner (user) event.save Other_user = User.create (: name = & gt; 'jack') event.add_user (another_user) < / Code>
Comments
Post a Comment