How to change "mpath" field name of materialized-path tree in typeorm? - typeorm

I hope you are well.
Is there any way to change the name of the "mpath" column that is automatically generated when using the materialized-path tree structure on typeorm?

Related

Update all rows in a column using data from another column in Rails

I have a Content model, where each piece of content has a source. Currently, the Content model has a link column for the URL and a link_text column for the name of the source, i.e. a user has to manually type in the name and URL of the source. I want to change this to be able to automatically enter a name, once a URL is provided. Here's what I did:
I made a Source model. The Source model contains all the name and domain of every source used for content. This is related to Content as follows: A Source has_many pieces of Content, while Content belongs to a Source.
Therefore, I need to replace the link_text column with a source_id column. Then I need to set the value of the source_id column using the link column in the contents table.
i.e. I will compare the URL in the link column (in the contents table) to the URL in the domain column (in the sources table) and set the source_id for each row of Content accordingly.
How could I go about doing that?
One other thing to consider is that, I want to set the source_id in a migration, so that I can make the change to existing data in my production application as well.
I have created 1 migration to add a source_id column to my contents table and another migration to set all the data in that column for all existing records - It's that second migration that I'm unsure about.

How can I replace records into another dataset?

I want to copy records of a few employees from one company into another larger one. If a primary key duplicate conflict occurs, the record has to be replaced. For Delphi DataSet there are commands "Insert", "Append", "Edit", and "Delete", but is there an easy way to "Replace" the record between the same tables, without knowing the full table structure or primary keys? There are like 30+ fields and they may be changed in the future.
In MySQL it would be REPLACE INTO table2 (SELECT * FROM table1) but I wanted to change a few fields in the target table, like employee's ID and department codes.
I'm afraid there is no way to replace/overwrite dataset records in Delphi. But using MySQL I can select the source data into a temp table, modify the temp table data, and place it into target table.

How to get IQueryable.ToList() with database fieldnames instead of entity properties

The scenario:
I have a considerable amount of entities as models in CodeFirst mapped to the database fieldname with the Attribute [Column("str")].
I have a bunch of Reporting Service Reports (in local-mode) with the DataSets mapped to the database field names.
I can't pass direct results of linq queries to those reports with the ToList() method because of the field names. What I can do (and I'm trying to avoid) is to type select new for each object; or run each query via a different datasource.
Question:
I would like to know if there is any trick to have a IQueryable object with the original field names instead of the property names. Something like a dynamic select new.
Any suggestions will be appreciated.
No, there isn't. The database column names either have to match the property name, or you have to use the Column attribute to make them line up. That's your only choices.

Entity Framework 4.1 Code First - How to map a string containing csv of Entity ID's (foreign keys) to the corresponding Entity

Before I submit my question, please be aware that I'm working with an existing database owned by a third party vendor, so unfortunately changing the database format is not an option.
Here's the issue: I have an Entity mapped to a database table that has a varchar column that contains one to many foreign keys in csv format. Those foreign keys correspond to the ID's of another Entity type. What I've been doing is writing a function that creates a List of ID's from that csv list and then I search for that Entity through the DBContect object. What I'd like to do is map a relationship between the entities. Is there a way to do that? Thanks!
Unfortunately there is no way to do that without changes in the database. EF is ORM tool but it is still very dependent on correctness of database design. Storing multiple values in single column is breaking even first database normal form. For EF your column containing csv data is single string value and you cannot make relation on that value.
Btw. it is even more complicated because the column cannot represent one-to-many relation in standard relational meaning - that would require dependent entities to contain Id of your master entity, not that master entity contains Ids of all dependent entities.

Is it possible to sort a TDBGrid on a lookup field?

I have a DBGrid with a column based on a lookup field.
How can I set it up so that when a user clicks on the column title, it will sort by that field.
My problem here is that I can't figure out a way to create an index on a lookup field.
I'm using Absolute Database for this, but most things that work with the BDE or TClientDataSet will work with Absolute.
Thanks!
I don't think it is possible to create an index on a lookup field. It is possible to create an index on an internally calculated field of a ClientDataSet though. In the OnCalcFields event handler set its value to the value of the lookup field. And set the visible property of the lookup field to false. Now you can sort on the internally calculated field.
What you could do (especially if the data is readonly, and does not have zillions of rows) is use a ClientDataSet to display data in your grid.
Roughly the steps would be like this:
Load the data from your regular into the ClientDataSet,
add a calculated field to the ClientDataSet that contains the value obtained from the lookup,
then add an index to that calculated
field.
--jeroen
You cannot sort by a lookup field. But you can 'fake' this. Let's suppose that you have the following tables: (PK means Primary Key)
Contacts
ID - Integer (PK)
NAME - Varchar(40)
COUNTRYID - Integer
Countries
ID - Integer (PK)
NAME - Varchar(40)
Then you can have the following query in the dataset which is linked to the TDBGrid:
SELECT C.ID, C.NAME, C.COUNTRYID, CO.NAME
FROM CONTACTS C
JOIN COUNTRIES CO ON C.COUNTRYID=CO.ID
(Not tested but I think that you got the idea)
Also you can put this in a view.
Then you'll display in your TDBGrid (as columns) only the ID, NAME and the desired lookup field which you already have (let's call it COUNTRYLOOK).
When one clicks on the Title Header you can change the query by adding in the 4th line an ORDER BY . For the specific column of the lookup field (COUNTRYLOOK), instead of using the 1:1 mapping you can put in the 4th line of your query ORDER BY CO.NAME. Reopen the query and that's it. In practice is much more simpler than my description here.
DevExpress ExpressQuantumGrid can do it, check it out:
http://www.devexpress.com/products/vcl/exquantumgrid/

Resources