How to create a record to related table from Seeder in Laravel 9 - laravel-9

I have a Seeder for table article in Laravel 9 and need to create related record to table comment.
I have this code in ArticleSeeder:
$articleResponse = $client->get($nextPage);
$articles = $articleResponse->getBody();
$articleData = json_decode($articles, true);
$createdArticle = \App\Models\Article::create($articleData);
//Fetch related comment data and save
$commentData['planet_id'] = $createdArticle->id;
\App\Models\Comment::create($commentData);
What's proper way to do this? I'm not sure it's a good way to put at all into Seeder.

Related

cross tab/pivoting in pentaho CDE

I am trying to create a dynamic pivoting in postgresql. my query is including 3 dimensions in which one includes a case statement. and one measure. I have tried various solutions found on web but none is working.
I am looking for a script which converts normal query to a pivoted table. pls help me with this.
You have 3 options, basically:
write your query in MDX, which can easily return a pivoted table; requires Mondrian schema first;
use a Kettle datasource and denormalise your data with PDI;
write a denormalisation function in your postFetch method of the table component: it gets the data coming from the query and manipulates it before passing it to the table renderer.
Code snippet to guide you through the process of denormalising in the postFetch of the component:
function(data){
var resultset = data.resultset;
var metadata = data.metadata;
// doStuff - this is the bit you'll have to code according to your needs. The resultset array has 1 element for each row of data; the metadata array holds metadata info such as colName, colType and output index.
var newResultset = someFunction(resultset);
var newMetadata = someOtherFunction(metadata);
// set data to the new values
data.resultset = newResultset;
data.metadata = newMetadata;
// return the modified data object to the component
return data;
}

oxid import old data SQL

I have an old oxid-version. I exported my old seo-data from the table "oxseo" to get the keywords and description for each article. Now i want to import these fields in my new version of the shop. My articles are already there, but not the seodata.
My first idea was to collect all the data i need from a csv-export of my old data.
For example, my output array could look something like:
$article = array();
$keywords = array();
$desc = array();
foreach($line as $l) {
$keywords[$i] = current_keyword
$desc[$i] = current_description
$oxid[$i] = current_oxid
}
So lets just assume I already have my filled array.
If i check the oxid's, they are still the same. So, from my exported CSV, picking a random OXID, looking for it in my new DB shows me the correct article.
Now my first thought was, to look in oxobject2seodata. I know that the data for the articles are stored in there, but i can't find a way to connect those, since the "oxid" from the old version is not the same as the objectId in the new version. In oxarticles, however, there is no "objectId".
Thank you in advance for any hints and tips
The field OXID in oxarticles table should match the field OXOBJECTID in oxobject2seodata table.
SELECT oa.OXID, o2s.* from oxobject2seodata o2s, oxarticles oa WHERE o2s.OXOBJECTID = oa.OXID AND oa.OXID = '[OXID-of-article]';
-- or
SELECT o2s.* from oxobject2seodata o2s WHERE o2s.OXOBJECTID = '[OXID-of-article]';

Joomla: how to load JTable-element with LIKE-condition

I am using the following code to load a categorys record:
$res = JTable::getInstance('category');
$res->load(array('id' => $catid));
Now I would like to load the record based on its title which whould be matched against a SQL LIKE-pattern - is it possible to do this in a simple way with JTable, or do I need $dbo?
Far as I know JTable is made to be simple and carry only one element at a time, and through the primary key. If you really want something more advanced, I recomend that you use JDatabaseQuery way.
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Select all articles for users who have a username which starts with 'a'.
// Order it by the created date.
$query
->select(array('a.*', 'b.username', 'b.name'))
->from('#__content AS a')
->join('INNER', '#__users AS b ON (a.created_by = b.id)')
->where('b.username LIKE \'a%\'')
->order('a.created DESC');
// Reset the query using our newly populated query object.
$db->setQuery($query);
// Load the results as a list of stdClass objects.
$results = $db->loadObjectList();
In your case, instead of "$db->loadObjectList();" you can use "$db->loadObject();" for load just one item.
Source:
http://docs.joomla.org/Accessing_the_database_using_JDatabase/3.1

How to create secondary index in Cassandra Hector API programmatically

I have been trying to create indexing using below set of lines.
KeyspaceDefinition fromCluster = cluster.describeKeyspace(KEYSPACE);
ColumnFamilyDefinition cfDef = fromCluster.getCfDefs().get(0);
BasicColumnFamilyDefinition columnFamilyDefinition = newBasicColumnFamilyDefinition(cfDef);
BasicColumnDefinition columnDefinition = new BasicColumnDefinition();
columnDefinition.setName(StringSerializer.get().toByteBuffer("A_NO"));
columnDefinition.setIndexName("A_NO_idx");
columnDefinition.setIndexType(ColumnIndexType.KEYS);
columnDefinition.setValidationClass(ComparatorType.UTF8TYPE.getClassName());
columnFamilyDefinition.addColumnDefinition(columnDefinition);
But i am unable to do so. Actually i am storing the data in the columns dynamically as well as creating those columns dynamically and after that for better query purpose i am trying to put index on some particular columns. Any suggestion please how to do that.
Its eventually quite simple. You just have to create the secondary index while defining your columnfamily. In the above code, all the manipulation are done on the object index which has to be created while defining only. The steps for adding index are
List<ColumnDef> columns = new ArrayList<ColumnDef>();
columns.add(newIndexedColumnDef("columnName", "UTF8Type"));
List<ColumnDefinition> columnMetadata = ThriftColumnDef
.fromThriftList(columns);
cdefs.add(cf_def); //cf_def is your columnfamily definition
The helper method code is from KeyspaceCreationTest
public ColumnDef newIndexedColumnDef(String column_name, String comparer){
ColumnDef cd = new ColumnDef(se.toByteBuffer(column_name), comparer);
cd.setIndex_name(column_name);
cd.setIndex_type(IndexType.KEYS);
return cd;
}
References for comparer can be found here
I hope it will help you.

Return newly inserted row without having to Submit to database

I need to find a way to get the newly insert row, without previously having to save to the database.
Is there a way? Or I need to keep the whole collection of row in a separated array?
Is this example I adding a row to the table tblConfig, but when I look back in the table the new row is not there.
tblConfig Config = new tblConfig { ID = Guid.NewGuid(), Code ="new config code" };
CTX.tblConfig.InsertOnSubmit(Config);
var Data = from dd in CTX.tblConfig select dd;
this.dataGridView1.DataSource = Data;
After some research , I'll do the work by attaching my LINQ query to a BindingSource object, witch will help me handle with insertion update and so.
Thanks for everyone, for your help :)
Hugo
Could you add that manually like this?
this.dataGridView1.DataSource = CTX.tblConfig.Execute(MergeOption.AppendOnly);