Project: Okul Database · Hub: Okul Database — Relationships

Complete Model Relationships

Extracted from 313 models (146 API + 167 Platform). 771 total relationships.


School (62 relationships — most connected model)

School hasMany:
  → SchoolFilter           (school_filters.school_id)
  → SchoolStatistic        (school_statistics.school_id)
  → Campus                 (campuses.school_id)
  → SchoolDetail           (school_details.school_id)
  → SchoolFee              (school_fees.school_id)
  → SchoolFeature          (school_features.school_id)
  → SchoolFacility         (school_facilities.school_id) pivot: facilities
  → SchoolService          (school_services.school_id)   pivot: services
  → SchoolShift            (school_shifts.school_id)     pivot: shifts
  → SchoolLearningLanguage (school_learning_languages.school_id)
  → SchoolLocation         (school_locations.school_id)
  → SchoolContact          (school_contacts.school_id)
  → SchoolComment          (school_comments.school_id)
  → SchoolAnnouncement     (school_announcements.school_id)
  → SchoolOffer            (school_offers.school_id)
  → SchoolInteraction      (school_interactions.school_id)
  → SchoolDailyLog         (school_daily_logs.school_id)
  → SchoolNameChange       (school_name_changes.school_id)
  → SchoolTag              (taggables WHERE taggable_type='School')
  → SchoolBadge            (school_badges.school_id)
  → SchoolProductPrice     (school_product_prices.school_id)
  → SchoolInboundCallLog   (school_inbound_call_logs.school_id)
  → SchoolActivity         (school_activities.school_id)
  → SchoolNote             (school_notes.school_id)
  → SchoolReferral         (school_referrals.school_id)
  → SchoolAchievementGrant (school_achievement_grants.school_id)
  → Lead                   (leads.school_id)
  → Discount               (discounts.school_id)
  → Scholarship            (scholarships.school_id) via school_scholarships
  → Gallery                (galleries WHERE school_id)
  → Media                  (media WHERE media_type_id=2, row_id=school_id)
  → PySchool               (py_schools.school_id)
  → HighSchool             (high_schools.school_id)

School belongsTo:
  → SchoolType / SchoolsTypes  (schools_types.id)
  → Sector / Sectors           (sectors.id)
  → College                    (colleges.id)
  → Customer                   (customers.id)
  → Campus (default campus)    (campuses.id)

School belongsToMany:
  → College  (via college_schools)
  → Tag      (via taggables, morph)

SchoolFilter (35 relationships)

SchoolFilter belongsTo:
  → School     (schools.id)
  → SchoolType (schools_types.id)
  → Sector     (sectors.id)
  → Customer   (customers.id)
  → Campus     (campuses.id)
  → College    (colleges.id)
  → Product    (products.id)
  → ProductPrice (product_prices.id)
  → Location city   (locations.id)
  → Location county (locations.id)

Customer (17 relationships)

Customer hasMany:
  → CustomerUser             (customer_users.customer_id)
  → CustomerAgreement        (customer_agreements.customer_id)
  → CustomerScore            (customer_scores.customer_id)
  → CustomerCreditCard       (customer_credit_cards.customer_id)
  → CustomerAgreementsRenewDiscount
  → SchoolInteraction        (school_interactions.customer_id)
  → Lead                     (leads.customer_id)
  → Payment                  (payments.customer_id)

Customer hasMany through:
  → School via CustomerAgreement

Customer belongsTo:
  → Customer (redirect: customers.redirect_id → self)
  → Association

User (7 direct + many indirect)

User hasOne:
  → UserDetail   (user_details.user_id)

User hasMany:
  → Lead         (leads.user_id)       — leads assigned to this user
  → SchoolOffer  (school_offers.user_id)
  → UserFavorite (user_favorites.user_id)
  → UserLog      (user_logs.user_id)
  → UserContact  (user_contacts.user_id)

User belongsTo:
  → Customer     (customers.id via users.customer_id)
  → UserType     (users_types.id)

User belongsToMany:
  → Role         (via model_has_roles)
  → Permission   (via model_has_permissions)

CustomerAgreement

CustomerAgreement belongsTo:
  → Customer      (customers.id)
  → SalesCampaign (sales_campaigns.id)
  → ProductPrice  (product_prices.id)

CustomerAgreement hasMany:
  → Payment                           (payments.customer_agreement_id)
  → CustomerAgreementsRenewLog        (customer_agreements_renew_logs.customer_agreement_id)
  → CustomerAgreementRenewDiscount    (customer_agreements_renew_discounts.customer_agreement_id)
  → CustomerUserAgreementSign         (customer_user_agreement_signs.customer_agreement_id)

Lead

Lead belongsTo:
  → School    (schools.id)
  → Campus    (campuses.id)
  → Customer  (customers.id)
  → User      (users.id)            — assigned agent
  → SchoolOffer (school_offers.id)
  → LeadPoolForm (lead_pool_forms.id)

Lead hasMany:
  → PipedriveDeal (pipedrive_deals.lead_id)

Payment

Payment belongsTo:
  → Customer           (customers.id)
  → CustomerAgreement  (customer_agreements.id)
  → ProductPrice       (product_prices.id)
  → InflationRate      (inflation_rates.id)

Payment hasMany:
  → PaymentTransaction (payment_transactions.payment_id)

SchoolInteraction

SchoolInteraction belongsTo:
  → School       (schools.id)
  → Campus       (campuses.id)
  → Customer     (customers.id)
  → CustomerUser (customer_users.id)

Media (Polymorphic)

Media belongsTo:
  → MediaType  (media_types.id)
  → MediaRole  (media_roles.id)
  → User (uploaded_by)

Morphed by (media_type_id + row_id):
  → School        (media_type_id=2)
  → Article       (media_type_id=1)
  → College       (media_type_id=4)
  → Gallery       (media_type_id=5)
  → Announcement  (media_type_id=6)
  → Scholarship   (media_type_id=7)
  → CustomerAgreement (media_type_id=8)

Product → ProductPrice → SchoolProductPrice

Product hasMany:
  → ProductPrice        (product_prices.product_id)

ProductPrice hasMany:
  → SchoolProductPrice  (school_product_prices.product_price_id)
  → Payment             (payments.product_price_id)
  → CustomerAgreement   (customer_agreements.product_price_id)

ProductPrice belongsTo:
  → Product   (products.id)
  → Location  (locations.id) — city-based pricing
  → SchoolType (schools_types.id)

Campus

Campus belongsTo:
  → School    (schools.id)
  → Location  (locations.id)

Campus hasMany:
  → SchoolLocation (school_locations.campus_id)
  → SchoolInteraction (school_interactions.campus_id)
  → Lead       (leads.campus_id)

CustomerUser

CustomerUser belongsTo:
  → Customer  (customers.id)
  → User      (users.id)

CustomerUser hasMany:
  → CustomerUserSchool  (customer_user_schools.customer_user_id)
  → CustomerUserDailyActivityLog
  → FamilyNote
  → FamilyAppointment

CustomerUser belongsToMany:
  → School   (via customer_user_schools)

High School Hierarchy

HighSchool belongsTo:
  → School         (schools.id)
  → HighSchoolType (high_schools_types.id)

HighSchoolType hasMany:
  → HighSchoolTypeDepartment (high_school_type_departments.high_school_type_id)

HighSchoolTypeDepartment hasMany:
  → HighSchoolDepartmentName   (via department_name_id)
  → HighSchoolDepartmentCourse (via department_course_id)

HighSchoolPoint belongsTo:
  → School           (schools.id)
  → HighSchoolType   (high_schools_types.id)
  → LearningLanguage (learning_languages.id)
  → Location city    (locations.id)
  → Location county  (locations.id)

University → Faculty → FacultyProgram

University hasMany:
  → Faculty (via faculties WHERE university_id — or via join)

Faculty hasMany:
  → FacultyProgram (faculty_programs.faculty_id)

FacultyProgram hasMany:
  → FacultyProgramInfo (faculty_program_info.faculty_program_id)
  → FacultyProgramWinner (faculty_program_winners.faculty_program_id)

FacultyProgramInfo belongsTo:
  → FacultyProgramInfoType (faculty_program_info_types.id)

Family

Family hasMany:
  → FamilyParent      (via family_parent pivot)
  → FamilyStudent     (via family_student pivot)
  → FamilyAppointment (family_appointments.family_id)
  → FamilyNote        (family_notes.family_id)

Family belongsToMany:
  → Parent  (via family_parent pivot table)
  → Student (via family_student pivot table)

Checkout

Checkout belongsTo:
  → User           (users.id)
  → CustomerUser   (customer_users.id)
  → School         (schools.id)
  → SalesCampaign  (sales_campaigns.id)
  → Discount       (discounts.id)