-
Notifications
You must be signed in to change notification settings - Fork 447
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
pkp/pkp-lib#10133 Port Genre and GenreDAO to Use Eloquent Model #10194
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @Hafsa-Naeem, I've added some comments but I think the biggest thing is to agree on some conventions WRT the settings table and collectors -- feel free to clean up some details, then let's make sure we've got those conventions figured out before continuing!
// Relationships | ||
public function submissionFiles(): HasMany | ||
{ | ||
return $this->hasMany(SubmissionFile::class, 'genre_id'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this should be genre_id
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used this relationship definition because in the database schema, genre_id
is used as the foreign key in submission_files
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I misread this, thanks!
// Accessors and Mutators | ||
protected function entryKey(): Attribute | ||
{ | ||
return Attribute::make( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there an equivalent to this in the previous implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the previous implementation we used getter and setter methods for entryKey
public function getKey()
{
return $this->getData('key');
}
public function setKey($key)
{
$this->setData('key', $key);
}
and in the new Eloquent this is replaced with
protected function entryKey(): Attribute
{
return Attribute::make(
get: fn($value) => strtoupper($value),
set: fn($value) => strtolower($value)
);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the uppercase/lowercase conversion I was wondering about; if it didn't exist in the previous code, best not to add it here.
); | ||
} | ||
|
||
protected function enabled(): Attribute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're just looking to cast a PHP boolean into a database int...
- It might be better to use attribute casting, or
- better still, just leave it an integer and at some point we'll declare boolean columns in the DB with the
boolean
type so that everything matches nicely without needing casting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this class still be required after the move to Eloquent is completed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asmecher No. it's temporary until the settings table handling is sorted out.
/** | ||
* Get enabled genres by context ID. | ||
* | ||
* @param int $contextId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @param
phpdocs don't add anything that's not already in the function declaration, so please remove them. (Here and below.)
} | ||
|
||
return $query->get(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a blank space between function declarations.
for #10133