Fix - vector of float & double does not derive Eq (#1158)
* Fix - vector of float & double does not derive Eq * clippy Co-authored-by: Chris Tsang <chris.2y3@outlook.com>
This commit is contained in:
parent
1497c2c7f0
commit
5e0c625ac0
@ -152,14 +152,16 @@ impl Entity {
|
||||
}
|
||||
|
||||
pub fn get_eq_needed(&self) -> TokenStream {
|
||||
fn is_floats(col_type: &sea_query::ColumnType) -> bool {
|
||||
match col_type {
|
||||
ColumnType::Float(_) | ColumnType::Double(_) => true,
|
||||
ColumnType::Array(col_type) => is_floats(col_type),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
self.columns
|
||||
.iter()
|
||||
.find(|column| {
|
||||
matches!(
|
||||
column.col_type,
|
||||
ColumnType::Float(_) | ColumnType::Double(_)
|
||||
)
|
||||
})
|
||||
.find(|column| is_floats(&column.col_type))
|
||||
// check if float or double exist.
|
||||
// if exist, return nothing
|
||||
.map_or(quote! {, Eq}, |_| quote! {})
|
||||
|
@ -1158,6 +1158,37 @@ mod tests {
|
||||
name: "id".to_owned(),
|
||||
}],
|
||||
},
|
||||
Entity {
|
||||
table_name: "collection_float".to_owned(),
|
||||
columns: vec![
|
||||
Column {
|
||||
name: "id".to_owned(),
|
||||
col_type: ColumnType::Integer(Some(11)),
|
||||
auto_increment: true,
|
||||
not_null: true,
|
||||
unique: false,
|
||||
},
|
||||
Column {
|
||||
name: "floats".to_owned(),
|
||||
col_type: ColumnType::Array(SeaRc::new(Box::new(ColumnType::Float(None)))),
|
||||
auto_increment: false,
|
||||
not_null: true,
|
||||
unique: false,
|
||||
},
|
||||
Column {
|
||||
name: "doubles".to_owned(),
|
||||
col_type: ColumnType::Array(SeaRc::new(Box::new(ColumnType::Double(None)))),
|
||||
auto_increment: false,
|
||||
not_null: true,
|
||||
unique: false,
|
||||
},
|
||||
],
|
||||
relations: vec![],
|
||||
conjunct_relations: vec![],
|
||||
primary_keys: vec![PrimaryKey {
|
||||
name: "id".to_owned(),
|
||||
}],
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
@ -1182,7 +1213,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_gen_expanded_code_blocks() -> io::Result<()> {
|
||||
let entities = setup();
|
||||
const ENTITY_FILES: [&str; 9] = [
|
||||
const ENTITY_FILES: [&str; 10] = [
|
||||
include_str!("../../tests/expanded/cake.rs"),
|
||||
include_str!("../../tests/expanded/cake_filling.rs"),
|
||||
include_str!("../../tests/expanded/filling.rs"),
|
||||
@ -1192,8 +1223,9 @@ mod tests {
|
||||
include_str!("../../tests/expanded/cake_with_float.rs"),
|
||||
include_str!("../../tests/expanded/cake_with_double.rs"),
|
||||
include_str!("../../tests/expanded/collection.rs"),
|
||||
include_str!("../../tests/expanded/collection_float.rs"),
|
||||
];
|
||||
const ENTITY_FILES_WITH_SCHEMA_NAME: [&str; 9] = [
|
||||
const ENTITY_FILES_WITH_SCHEMA_NAME: [&str; 10] = [
|
||||
include_str!("../../tests/expanded_with_schema_name/cake.rs"),
|
||||
include_str!("../../tests/expanded_with_schema_name/cake_filling.rs"),
|
||||
include_str!("../../tests/expanded_with_schema_name/filling.rs"),
|
||||
@ -1203,6 +1235,7 @@ mod tests {
|
||||
include_str!("../../tests/expanded_with_schema_name/cake_with_float.rs"),
|
||||
include_str!("../../tests/expanded_with_schema_name/cake_with_double.rs"),
|
||||
include_str!("../../tests/expanded_with_schema_name/collection.rs"),
|
||||
include_str!("../../tests/expanded_with_schema_name/collection_float.rs"),
|
||||
];
|
||||
|
||||
assert_eq!(entities.len(), ENTITY_FILES.len());
|
||||
@ -1264,7 +1297,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_gen_compact_code_blocks() -> io::Result<()> {
|
||||
let entities = setup();
|
||||
const ENTITY_FILES: [&str; 9] = [
|
||||
const ENTITY_FILES: [&str; 10] = [
|
||||
include_str!("../../tests/compact/cake.rs"),
|
||||
include_str!("../../tests/compact/cake_filling.rs"),
|
||||
include_str!("../../tests/compact/filling.rs"),
|
||||
@ -1274,8 +1307,9 @@ mod tests {
|
||||
include_str!("../../tests/compact/cake_with_float.rs"),
|
||||
include_str!("../../tests/compact/cake_with_double.rs"),
|
||||
include_str!("../../tests/compact/collection.rs"),
|
||||
include_str!("../../tests/compact/collection_float.rs"),
|
||||
];
|
||||
const ENTITY_FILES_WITH_SCHEMA_NAME: [&str; 9] = [
|
||||
const ENTITY_FILES_WITH_SCHEMA_NAME: [&str; 10] = [
|
||||
include_str!("../../tests/compact_with_schema_name/cake.rs"),
|
||||
include_str!("../../tests/compact_with_schema_name/cake_filling.rs"),
|
||||
include_str!("../../tests/compact_with_schema_name/filling.rs"),
|
||||
@ -1285,6 +1319,7 @@ mod tests {
|
||||
include_str!("../../tests/compact_with_schema_name/cake_with_float.rs"),
|
||||
include_str!("../../tests/compact_with_schema_name/cake_with_double.rs"),
|
||||
include_str!("../../tests/compact_with_schema_name/collection.rs"),
|
||||
include_str!("../../tests/compact_with_schema_name/collection_float.rs"),
|
||||
];
|
||||
|
||||
assert_eq!(entities.len(), ENTITY_FILES.len());
|
||||
|
17
sea-orm-codegen/tests/compact/collection_float.rs
Normal file
17
sea-orm-codegen/tests/compact/collection_float.rs
Normal file
@ -0,0 +1,17 @@
|
||||
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.0
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||
#[sea_orm(table_name = "collection_float")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub floats: Vec<f32> ,
|
||||
pub doubles: Vec<f64> ,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
@ -0,0 +1,17 @@
|
||||
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.0
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||
#[sea_orm(schema_name = "schema_name", table_name = "collection_float")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub floats: Vec<f32> ,
|
||||
pub doubles: Vec<f64> ,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
60
sea-orm-codegen/tests/expanded/collection_float.rs
Normal file
60
sea-orm-codegen/tests/expanded/collection_float.rs
Normal file
@ -0,0 +1,60 @@
|
||||
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.0
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
||||
pub struct Entity;
|
||||
|
||||
impl EntityName for Entity {
|
||||
fn table_name(&self) -> &str {
|
||||
"collection_float"
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
|
||||
pub struct Model {
|
||||
pub id: i32,
|
||||
pub floats: Vec<f32> ,
|
||||
pub doubles: Vec<f64> ,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
||||
pub enum Column {
|
||||
Id,
|
||||
Floats,
|
||||
Doubles,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
|
||||
pub enum PrimaryKey {
|
||||
Id,
|
||||
}
|
||||
|
||||
impl PrimaryKeyTrait for PrimaryKey {
|
||||
type ValueType = i32;
|
||||
fn auto_increment() -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ColumnTrait for Column {
|
||||
type EntityName = Entity;
|
||||
fn def(&self) -> ColumnDef {
|
||||
match self {
|
||||
Self::Id => ColumnType::Integer.def(),
|
||||
Self::Floats => ColumnType::Array(sea_orm::sea_query::SeaRc::new(ColumnType::Float)).def(),
|
||||
Self::Doubles => ColumnType::Array(sea_orm::sea_query::SeaRc::new(ColumnType::Double)).def(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RelationTrait for Relation {
|
||||
fn def(&self) -> RelationDef {
|
||||
panic!("No RelationDef")
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
@ -0,0 +1,64 @@
|
||||
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.0
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
||||
pub struct Entity;
|
||||
|
||||
impl EntityName for Entity {
|
||||
fn schema_name(&self) -> Option< &str > {
|
||||
Some("schema_name")
|
||||
}
|
||||
|
||||
fn table_name(&self) -> &str {
|
||||
"collection_float"
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
|
||||
pub struct Model {
|
||||
pub id: i32,
|
||||
pub floats: Vec<f32> ,
|
||||
pub doubles: Vec<f64> ,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
||||
pub enum Column {
|
||||
Id,
|
||||
Floats,
|
||||
Doubles,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
|
||||
pub enum PrimaryKey {
|
||||
Id,
|
||||
}
|
||||
|
||||
impl PrimaryKeyTrait for PrimaryKey {
|
||||
type ValueType = i32;
|
||||
fn auto_increment() -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ColumnTrait for Column {
|
||||
type EntityName = Entity;
|
||||
fn def(&self) -> ColumnDef {
|
||||
match self {
|
||||
Self::Id => ColumnType::Integer.def(),
|
||||
Self::Floats => ColumnType::Array(sea_orm::sea_query::SeaRc::new(ColumnType::Float)).def(),
|
||||
Self::Doubles => ColumnType::Array(sea_orm::sea_query::SeaRc::new(ColumnType::Double)).def(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RelationTrait for Relation {
|
||||
fn def(&self) -> RelationDef {
|
||||
panic!("No RelationDef")
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
Loading…
x
Reference in New Issue
Block a user