Subsonic 2.1 : Way to ignore a column while generating code? - subsonic

For some reason, a row named "rowguid" with a "uniqueidentifier" parameter was added to some tables on an already existing project. While regenerating the code, I found out that a method named "Insert(string Key)" was used, but doesn't exists anymore (it's now Insert(string Key, Guid varRowguid).
Is there a way to "ignore" a column while generating the code?
Note : The default of this new "rowguid" column is the Sql server method newsequentialid()
UPDATE : I added a "new System.GUId()" as a second parameter but I'd like to not have to modify the code...

With subsonic 2.1, you can edit the templates that are used to generate the code. I've added a "IF" and checked the "rowguid"... if it's the case, just ignore it.

Related

Pimcore 6 CSV Importing

Pimcore newbie here. I'm struggling a bit with the csv import procedure, the docs are a bit shallow and I couldn't find a more comprehensive developer reference.
I'm not getting how Resolver Settings work. What's the meaning of setting a strategy? (ID throws Pimcore\DataObject\Import\Resolver\ImportErrorException: Could not resolve object with id. Filename runs, but then it seems that I don't have control on how objects get labeled)
I have two date columns in my imported csv, so I'd like to fill my object with those. Still, the dates are written like "2016-05-30T14:36:03" so I guess that I need to process a bit to transform the string in a format that could be recognized by pimcore. Do I need to do this in Column Configuration (by converting the specific column as an Operator PHP Code. BTW, do I need to create a class for every column, or I can group them by data format?) or more globally by setting the Resolver Strategy as Code and editing all the row properties at once?
About the resolver
When importing a CSV, Pimcore has for each row basically two options: create a new DataObject or update an existing one. When you want Pimcore to update existing DataObjects then you need some logic to retrieve that specific DataObject based on some info in the CSV. That's where the Resolver comes in place.
Pimcore supports 5 different resolver strategies:
Id: your CSV needs to contain a column with the DataObject id, and that value is used to fetch the corresponding DataObject to update
Filename: same as above, but for the filename (= key) of the DataObject
Fullpath: same as above, but for the full path of the DataObject
GetByAttribute: same as above, but for a given attribute within the DataObject (for example if you have a field ProductCode in it)
Code: a custom PHP class containing logic to retrieve the existing DataObject
The Id operator has one drawback, which you are currently running into:
Resolves the objects via the object ID. The object has to exist, otherwise an error is thrown.
Based on your question, I have the feeling that you are only inserting new DataObjects (at least for now, maybe you might also want to update later on).
When creating DataObjects you need to specify a key/filename (most likely you already noticed that when creating an object manually), so your CSV should already (if it doesn't you should add it) contain a column with either that key/filename or with the full path for the new DataObjects. That same column can/should be used to resolve any (potentially already) existing DataObjects.
So you should use either the Filename or Fullpath Resolver. Both have options what to do if the object already exists (update it? ignore it?) and (more important in your situation) what to do when it doesn't exist yet.
About the dates
Looking at the code, any string that can be parsed by the PHP's method strtotime can be entered in your CSV. Your value 2016-05-30T14:36:03 parses just fine.

Kentico 11 System Generated GUID

Using Kentico 11 (Portal engine)
I would like to add a GUID field to one of my pagetypes. I would like the system to generate the guid (I assume this is done via a macro?). Any idea what macro might do the trick? Any help is appreciated.
I do not believe there is a macro which will generate a new GUID for you. You'd have to create a custom macro method to do that for you. The macro you're using won't work because the document isn't created at the time the macro is accessed. AND it wouldn't be unique either.
I had the same issue... I just ended up fixing it directly in SQL by adding default value:
ALTER TABLE [SomeTableName] ADD CONSTRAINT [ContraintName] DEFAULT NEWID() FOR [ColumName];
This is your custom column so you can set the value to whatever your want. I dont see any other use for GUID macro although it is not complicated thing to do.
For others that stumble upon this question in need of an auto-populating unique identifier field, I chose to use existing macro functions to piece together a unique string. This was a more appealing solution than going down the build-your-own macro path.
Here is the macro I used in the Default value field:
{% String.FormatString("{0:yyyyMMddhhmmssfffff}", CurrentDateTime) + Math.GetRandomInt(10000, 99999) #%}
Here's an example value:
201912200958109206631318
No, it's not technically a GUID. It does the job, though.

Extending Kuali Document Business Object

I am facing an issue with extended attributes on a document (trying to extend a document table). I created the original table’s PK (FDOC_NBR) in the extended table and linked the two via a foreignKey of the customized original table’s ojb entry (as an “extension” reference-descriptor). I created the bo and dd for the extension and customized the original document’s dd to add the new attributes. On the extended BO itself I also added members (with setters and getters) for the 2 new columns + for the PK column of documentNumber. I also added the new attributes to the documet’s jsp. The pertinent module definition was already extended to include custom dd, ojb, etc. files.
Indeed, when opening the document the new fields are shown- however, when trying to submit the document (regardless of doing anything with the new fields) I get an error-
Error Details: OJB operation; SQL []; ORA-01400: cannot insert NULL
into ("KFSTEM"."TEM_TRVL_ARRANGER_DOC_EXT_T"."FDOC_NBR") ; nested
exception is java.sql.SQLIntegrityConstraintViolationException:
ORA-01400: cannot insert NULL into
("KFSTEM"."TEM_TRVL_ARRANGER_DOC_EXT_T"."FDOC_NBR")
Seems like somehow the system tries to insert a value of NULL into the extension’s PK field, instead of the actual document number. Trying to debug this, in the action’s route method and all the way down to DocumentDaoOjb.save (which is as far down as I can go) I see the document with the real doc number is passed on, so the problem seems to be purely with ojb trying to set this number to the extension table.
Does anyone have any experience with extended attributes on documents that could help shed some light on this?
KFS is using the KNS, and in the Kuali Nervous System, the primary key on the extended attributes object must be set through manual intervention.
In this case, it looks as if you're adding an extended attribute to a transactional document, the Travel Arranger document (TAA), which simplifies things. Basically, you'll need to extend org.kuali.kfs.module.tem.document.TravelArrangerDocument and override prepareForSave to set the document number there (it may be set already since prepareForSave should be called several times during the routing process, but there's no real harm from overwriting that information as the base document's number will remain the same).
Hope this helps!

I'm missing functionalities on SubSonic 3

I'm starting to do some test on SubSonic 3 and I'm missing some stuff.
1st: Where's the Table names constants? The place where we could ask for the same of a certain table using intelisense...
2nd: Same as the above but for the table columns... where are they?
This is very useful mostly when you need to pass those names as string... it you need to refactor your DB we don't need to look through all the code to find where was I using that column!! Once you re-generate the code the compiler tells you!
3rd: Now how can I perform an ExecuteReader on a certain table like I'm used to on 2.x through the Query object? I used this a lot for list where I really don't need the business objects (BO) overhead... When I needed a BO (for showing a grid row details) I create it from the row itself...
I'm using ActiveRecord btw...
Thanks guys!
Alex
1st: Where's the Table names constants? The place where we could ask for the same of a certain table using intelisense...
In Structs.tt find the following line of code at line 47:
<# foreach(var col in tbl.Columns){#>
Add the following code above it:
public static string TableName { get { return "<#=tbl.Name#>"; } }
Now you'll have a property that returns the name of the table.
2nd: Same as the above but for the table columns... where are they?
In the generated Structs.cs file, this is included in the 3.0.0.3 version
3rd: Now how can I perform an ExecuteReader on a certain table like I'm used to on 2.x through the Query object? I used this a lot for list where I really don't need the business objects (BO) overhead... When I needed a BO (for showing a grid row details) I create it from the row itself...
If you're using SqlQuery object you can call ExecuteReader on it. Alternatively you can use Linq syntax to generate return custom shaped objects and they'll get mapped automatically.
1st and 2nd: It's not implemented in the default tt-files.
A similiar question:
SubSonic 3 Simple Query Tool
Problem is that's not a correct implementation if you want the 2.x way - the XColumn properties used to be column objects and not string constants, those were found under the Columns struct. So I hope that check-in will not be accepted and that someone will 2.x-ify it correctly.
Anyway as you can see it seems pretty easy to fix it on your own.

Automatically update AddedBy and EditedBy fields in SubSonic

I have a data model that includes common columns like addedBy, editedby (user), addedDate, editedDate.
Is there a setting I can use in SubSonic 2.1 that will automatically update these fields appropriately instead of having to explicitly specify in every update?
Check out http://subsonicproject.com/setup/subsonic-conventions/. SubSonic uses a convention-based approach when it comes to audit columns. If you can change your column names to CreatedBy, ModifiedBy, CreatedOn, and ModifiedOn respectively, then they will be updated automatically. I don't think there's a way to change what those names can be without making changes to the SubSonic source code.

Resources