Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Eloquent Relationship Name Case Sensitivity Issue with Oracle Database #2142

Open
ChandanShakya opened this issue Jan 2, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@ChandanShakya
Copy link

What happened?

When using Oracle database, the Eloquent relationship named 'examGroup' in the ExamType model is not working as expected. The relationship works correctly with MySQL and MariaDB, but fails with Oracle. The issue appears to be related to case sensitivity in relationship naming.

How to reproduce the bug

  1. Create an ExamType model with a relationship named 'examGroup'
  2. Try to access the relationship using ExamType::with('examGroup')->get()
  3. Works in MySQL/MariaDB but fails in Oracle

Package Version

3.5.10

PHP Version

8.3.x

Laravel Version

10.48.25

Alpine Version

3.14.8

Theme

Bootstrap 5.x

Notes

Code example:

// This doesn't work
// Model
class ExamType extends Model
{
    public function examGroup(): BelongsTo
    {
        return $this->belongsTo(ExamGroup::class, 'exam_group_id', 'id');
    }
}
// Table
Column::make('Exam Group', 'examGroup.group_name')
                ->sortable()->searchable(),


// This works
class ExamType extends Model
{
    public function exam_group(): BelongsTo
    {
        return $this->belongsTo(ExamGroup::class, 'exam_group_id', 'id');
    }
}
// Table
Column::make('Exam Group', 'exam_group.group_name')
                ->sortable()->searchable(),

Database Versions:

  • Oracle: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
  • MySQL: 10.8.0.40 (working)
  • MariaDB: 11.6.2 (working)

Notes:
The issue seems to be specific to Oracle's case-sensitive handling of column names and relationships. While MySQL and MariaDB handle the camelCase relationship name correctly, Oracle requires exact case matching with the database column names.

Additional Context:
This appears to be related to how Oracle handles identifier case-sensitivity differently from MySQL/MariaDB. The relationship name 'examGroup' doesn't properly map to the 'exam_group_id' column in Oracle's case-sensitive environment.

Error Message

Error Code : 904 Error Message : ORA-00904: "EXAM_GROUP"."ACADEMIC_YEAR": invalid identifier Help: https://docs.oracle.com/error-help/db/ora-00904/ Position : 302 Statement : select count(*) as aggregate from "EXAM_TYPES" left join "EXAM_GROUPS" examgroup on "EXAM_TYPES"."EXAM_GROUP_ID" = "EXAMGROUP"."ID" left join "USERS" user_creator on "EXAM_TYPES"."CREATED_BY" = "USER_CREATOR"."ID" left join "USERS" user_updater on "EXAM_TYPES"."UPDATED_BY" = "USER_UPDATER"."ID" where "EXAM_GROUP"."ACADEMIC_YEAR" = :p0 Bindings : [2081]

@ChandanShakya ChandanShakya added the bug Something isn't working label Jan 2, 2025
@lrljoe
Copy link
Collaborator

lrljoe commented Jan 4, 2025

Thanks for the detailed explanation.

I do note that OracleDB isn't natively supported by Eloquent etc still, which may explain the disparity in the naming convention.

Is it just the relationship naming that is behaving oddly? Is everything else working?

I'll try to spin up an Oracle example once I know more.
To help me replicate, can you let me know which packages (if any) you are using to implement OracleDB on your models?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants