Le samedi 05 mars 2016 à 13:42 -0800, Adrian Salceanu a écrit :
> Gentleman, I stumbled onto this one in my code, and despite trying
> all the possible combinations I could think of, no dice. 
> 
> I have this simple type hierarchy: 
> 
> abstract Model
> type Package <: Model
> type Repo <: Model
> 
> The Model type is an ORM and it defines a series of methods that
> operate on Model subtypes. 
> 
> ex: 
> function save{T<:Model}(m::T)
Note that this can be written more simply as:
function save(m::Model)

(the longer syntax is only useful when T is a parameter of another
argument type)

> So far so good. 
> 
> Now, according to ORM architecture and design patterns, an instance
> of a subtype represents a table row, while the class itself
> represents the table. And of course there are plenty of such
> methods. 
> For instance, the find_one_by function, which takes the type itself
> (the table). 
> 
> function find_one_by(m, column_name::SQLColumn, value::SQLInput) #
> this works, with m::Any
> 
> The question is, how can I define this method so that it accepts all
> the types of the subtypes of Model? 
> 
> I tried multiple combinations, such as: 
> function find_one_by{T<:Type{Model}}(m::T, column_name::SQLColumn,
> value::SQLInput)
> 
> none was good. :( Any ideas? 
Use this:
find_one_by{T<:Model}(m::Type{T}, ...



Regards

Reply via email to