Skip to content

Commit

Permalink
feat(BaseEntity): Add include and exclude arguments to fill method
Browse files Browse the repository at this point in the history
Similar functionality as Wirebox for being able to include/exclude properties from fill().

Co-authored-by: Eric Peterson <eric@elpete.com>
  • Loading branch information
homestar9 and elpete authored Oct 7, 2022
1 parent 1092a8e commit 030e674
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion models/BaseEntity.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,34 @@ component accessors="true" {
*
* @return quick.models.BaseEntity
*/
public any function fill( struct attributes = {}, boolean ignoreNonExistentAttributes = false ) {
public any function fill(
struct attributes = {},
boolean ignoreNonExistentAttributes = false,
any include = [],
any exclude = []
) {
// if they passed in a list instead of an array for include or exclude, convert it to an array
if ( isSimpleValue( arguments.include ) ) {
arguments.include = listToArray( arguments.include );
}

if ( isSimpleValue( arguments.exclude ) ) {
arguments.exclude = listToArray( arguments.exclude );
}

for ( var key in arguments.attributes ) {
// Include List?
if ( include.len() && !include.findNoCase( key ) ) {
continue;
}

// exclude list?
if ( exclude.len() && exclude.findNoCase( key ) ) {
continue;
}

guardAgainstReadOnlyAttribute( key );

if ( isNull( arguments.attributes[ key ] ) || !structKeyExists( arguments.attributes, key ) ) {
if ( hasAttribute( key ) ) {
clearAttribute( key, true );
Expand Down

0 comments on commit 030e674

Please sign in to comment.